pgadmin4 icon indicating copy to clipboard operation
pgadmin4 copied to clipboard

Add FORCE_QUOTE option to Import/Export Data in v9.x

Open aquarius777 opened this issue 9 months ago • 2 comments

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!

aquarius777 avatar Mar 21 '25 21:03 aquarius777

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.

akshay-joshi avatar Apr 21 '25 13:04 akshay-joshi

Instructions for QA on what to test:

  1. The copy command format should follow the new syntax mentioned in the PostgreSQL docs.
  2. Binary format export/import both should work.
  3. Text format export/import both should work.
  4. Added missing parametes FREEZE, DEFAULT (>=16), FORCE_QUOTE, FORCE_NULL, ON_ERROR (>=17) and LOG_VERBOSITY (>=17).
  5. 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 *"
  6. 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 *"

akshay-joshi avatar Apr 22 '25 12:04 akshay-joshi

This is working fine.

yogeshmahajan-1903 avatar May 21 '25 07:05 yogeshmahajan-1903