Add FORCE_QUOTE option to Import/Export Data in v9.x
I’d like the “Import/Export Data” tool in pgAdmin 4 (v9.1) to include a “Force Quote All Columns” checkbox in the Options tab. This would add the FORCE_QUOTE option to the underlying COPY command, ensuring all CSV values—header and data—are quoted with the specified quote character (e.g., ").
For example, with my table "simple" (columns a, b, c as VARCHAR), I export using Delimiter ; and Quote ", excluding column c. I currently get:
a;b 1;4 2;5 3;6 one;two
But I'd like to get:
"a";"b" "1";"4" "2";"5" "3";"6" "one";"two"
This would make exports consistent and easier to use in tools expecting fully quoted CSVs, without needing to switch to psql.
I’ve tried a few workarounds:
Using psql with \copy: This works perfectly with a command like: sql \copy (SELECT 'a' AS "a", 'b' AS "b" UNION ALL SELECT a, b FROM simple) TO 'C:\path\to\file.csv' WITH (FORMAT CSV, DELIMITER ';', QUOTE '"', FORCE_QUOTE ("a", "b"))
It gives me the quoted output I want, but it’s a hassle to leave pgAdmin, open psql, and write a custom query—especially for quick exports.
Thanks a lot!
Include all missing options of the COPY command and use the updated syntax format instead of the legacy-compatible version.
After testing, it seems that the BINARY option is not at all working, so fix that issue as well.
Instructions for QA on what to test:
- The copy command format should follow the new syntax mentioned in the PostgreSQL docs.
- Binary format export/import both should work.
- Text format export/import both should work.
- Added missing parametes FREEZE, DEFAULT (>=16), FORCE_QUOTE, FORCE_NULL, ON_ERROR (>=17) and LOG_VERBOSITY (>=17).
- Test the FORCE_QUOTE option with selected columns and all columns. If all columns are selected, then the copy command must have an option like "FORCE_QUOTE *"
- Test the FORCE_NOT_NULL and FORCE_NULL with selected columns and all columns. If all the columns are selected and the server version is >= 17, then the copy command must have an option like "FORCE_NOT_NULL *" Or "FORCE_NULL *"
This is working fine.