From 65755fdca4c2e9508edebbe9d429fb1ecbaad944 Mon Sep 17 00:00:00 2001 From: Joel Jacobson Date: Sat, 19 Oct 2024 07:32:05 +0200 Subject: [PATCH] Improve incorrect COPY options tests. - Rearranged incorrect options tests into three categories: 1. Incorrect COPY {FROM|TO} options 2. Incorrect COPY FROM options 3. Incorrect COPY TO options - Rewrote FORCE_QUOTE and ON_ERROR tests to ensures testing a single error condition, improving clarity and test specificity, and avoids reliance on the order of checks in ProcessCopyOptions: -COPY x from stdin (format TEXT, force_quote(a)); -COPY x from stdin (format TEXT, force_quote *); +COPY x to stdout (format TEXT, force_quote(a)); +COPY x to stdout (format TEXT, force_quote *); -COPY x to stdout (format BINARY, on_error unsupported); +COPY x to stdout (format BINARY, on_error ignore); - Added missing incorrect options tests for ESCAPE and QUOTE: +COPY x from stdin (format TEXT, escape 'x'); +COPY x from stdin (format BINARY, escape 'x'); +COPY x from stdin (format TEXT, quote 'x'); +COPY x from stdin (format BINARY, quote 'x'); --- src/test/regress/expected/copy2.out | 52 +++++++++++++++++------------ src/test/regress/sql/copy2.sql | 26 ++++++++++----- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/test/regress/expected/copy2.out b/src/test/regress/expected/copy2.out index 64ea33aeae..c79282c0b3 100644 --- a/src/test/regress/expected/copy2.out +++ b/src/test/regress/expected/copy2.out @@ -85,25 +85,38 @@ COPY x from stdin (log_verbosity default, log_verbosity verbose); ERROR: conflicting or redundant options LINE 1: COPY x from stdin (log_verbosity default, log_verbosity verb... ^ --- incorrect options +-- incorrect COPY {FROM|TO} options COPY x from stdin (format BINARY, delimiter ','); ERROR: cannot specify DELIMITER in BINARY mode COPY x from stdin (format BINARY, null 'x'); ERROR: cannot specify NULL in BINARY mode +COPY x from stdin (format TEXT, escape 'x'); +ERROR: COPY ESCAPE requires CSV mode +COPY x from stdin (format BINARY, escape 'x'); +ERROR: COPY ESCAPE requires CSV mode +COPY x from stdin (format TEXT, quote 'x'); +ERROR: COPY QUOTE requires CSV mode +COPY x from stdin (format BINARY, quote 'x'); +ERROR: COPY QUOTE requires CSV mode +COPY x from stdin (log_verbosity unsupported); +ERROR: COPY LOG_VERBOSITY "unsupported" not recognized +LINE 1: COPY x from stdin (log_verbosity unsupported); + ^ +-- incorrect COPY FROM options COPY x from stdin (format BINARY, on_error ignore); ERROR: only ON_ERROR STOP is allowed in BINARY mode COPY x from stdin (on_error unsupported); ERROR: COPY ON_ERROR "unsupported" not recognized LINE 1: COPY x from stdin (on_error unsupported); ^ -COPY x from stdin (format TEXT, force_quote(a)); -ERROR: COPY FORCE_QUOTE requires CSV mode -COPY x from stdin (format TEXT, force_quote *); -ERROR: COPY FORCE_QUOTE requires CSV mode -COPY x from stdin (format CSV, force_quote(a)); -ERROR: COPY FORCE_QUOTE cannot be used with COPY FROM -COPY x from stdin (format CSV, force_quote *); -ERROR: COPY FORCE_QUOTE cannot be used with COPY FROM +COPY x from stdin with (on_error ignore, reject_limit 0); +ERROR: REJECT_LIMIT (0) must be greater than zero +COPY x from stdin with (reject_limit 1); +ERROR: COPY REJECT_LIMIT requires ON_ERROR to be set to IGNORE +COPY x to stdout (format BINARY, on_error ignore); +ERROR: COPY ON_ERROR cannot be used with COPY TO +LINE 1: COPY x to stdout (format BINARY, on_error ignore); + ^ COPY x from stdin (format TEXT, force_not_null(a)); ERROR: COPY FORCE_NOT_NULL requires CSV mode COPY x from stdin (format TEXT, force_not_null *); @@ -120,18 +133,15 @@ COPY x to stdout (format CSV, force_null(a)); ERROR: COPY FORCE_NULL cannot be used with COPY TO COPY x to stdout (format CSV, force_null *); ERROR: COPY FORCE_NULL cannot be used with COPY TO -COPY x to stdout (format BINARY, on_error unsupported); -ERROR: COPY ON_ERROR cannot be used with COPY TO -LINE 1: COPY x to stdout (format BINARY, on_error unsupported); - ^ -COPY x from stdin (log_verbosity unsupported); -ERROR: COPY LOG_VERBOSITY "unsupported" not recognized -LINE 1: COPY x from stdin (log_verbosity unsupported); - ^ -COPY x from stdin with (reject_limit 1); -ERROR: COPY REJECT_LIMIT requires ON_ERROR to be set to IGNORE -COPY x from stdin with (on_error ignore, reject_limit 0); -ERROR: REJECT_LIMIT (0) must be greater than zero +-- incorrect COPY TO options +COPY x to stdout (format TEXT, force_quote(a)); +ERROR: COPY FORCE_QUOTE requires CSV mode +COPY x to stdout (format TEXT, force_quote *); +ERROR: COPY FORCE_QUOTE requires CSV mode +COPY x from stdin (format CSV, force_quote(a)); +ERROR: COPY FORCE_QUOTE cannot be used with COPY FROM +COPY x from stdin (format CSV, force_quote *); +ERROR: COPY FORCE_QUOTE cannot be used with COPY FROM -- too many columns in column list: should fail COPY x (a, b, c, d, e, d, c) from stdin; ERROR: column "d" specified more than once diff --git a/src/test/regress/sql/copy2.sql b/src/test/regress/sql/copy2.sql index 45273557ce..ae584ec348 100644 --- a/src/test/regress/sql/copy2.sql +++ b/src/test/regress/sql/copy2.sql @@ -69,15 +69,21 @@ COPY x from stdin (encoding 'sql_ascii', encoding 'sql_ascii'); COPY x from stdin (on_error ignore, on_error ignore); COPY x from stdin (log_verbosity default, log_verbosity verbose); --- incorrect options +-- incorrect COPY {FROM|TO} options COPY x from stdin (format BINARY, delimiter ','); COPY x from stdin (format BINARY, null 'x'); +COPY x from stdin (format TEXT, escape 'x'); +COPY x from stdin (format BINARY, escape 'x'); +COPY x from stdin (format TEXT, quote 'x'); +COPY x from stdin (format BINARY, quote 'x'); +COPY x from stdin (log_verbosity unsupported); + +-- incorrect COPY FROM options COPY x from stdin (format BINARY, on_error ignore); COPY x from stdin (on_error unsupported); -COPY x from stdin (format TEXT, force_quote(a)); -COPY x from stdin (format TEXT, force_quote *); -COPY x from stdin (format CSV, force_quote(a)); -COPY x from stdin (format CSV, force_quote *); +COPY x from stdin with (on_error ignore, reject_limit 0); +COPY x from stdin with (reject_limit 1); +COPY x to stdout (format BINARY, on_error ignore); COPY x from stdin (format TEXT, force_not_null(a)); COPY x from stdin (format TEXT, force_not_null *); COPY x to stdout (format CSV, force_not_null(a)); @@ -86,10 +92,12 @@ COPY x from stdin (format TEXT, force_null(a)); COPY x from stdin (format TEXT, force_null *); COPY x to stdout (format CSV, force_null(a)); COPY x to stdout (format CSV, force_null *); -COPY x to stdout (format BINARY, on_error unsupported); -COPY x from stdin (log_verbosity unsupported); -COPY x from stdin with (reject_limit 1); -COPY x from stdin with (on_error ignore, reject_limit 0); + +-- incorrect COPY TO options +COPY x to stdout (format TEXT, force_quote(a)); +COPY x to stdout (format TEXT, force_quote *); +COPY x from stdin (format CSV, force_quote(a)); +COPY x from stdin (format CSV, force_quote *); -- too many columns in column list: should fail COPY x (a, b, c, d, e, d, c) from stdin; -- 2.45.1