Skip to content

Commit

Permalink
Add more tests for COPY with incorrect option combinations
Browse files Browse the repository at this point in the history
Based on the existing coverage report, some combinations were not
checked at all, so add some tests to do so.  Spotted while looking at
the area.

Discussion: https://postgr.es/m/[email protected]
  • Loading branch information
michaelpq committed Nov 2, 2022
1 parent e7c7605 commit 451d116
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/regress/expected/copy2.out
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ COPY x from stdin (encoding 'sql_ascii', encoding 'sql_ascii');
ERROR: conflicting or redundant options
LINE 1: COPY x from stdin (encoding 'sql_ascii', encoding 'sql_ascii...
^
-- incorrect options
COPY x to stdin (format BINARY, delimiter ',');
ERROR: cannot specify DELIMITER in BINARY mode
COPY x to stdin (format BINARY, null 'x');
ERROR: cannot specify NULL in BINARY mode
COPY x to stdin (format TEXT, force_quote(a));
ERROR: COPY force quote available only in CSV mode
COPY x from stdin (format CSV, force_quote(a));
ERROR: COPY force quote only available using COPY TO
COPY x to stdout (format TEXT, force_not_null(a));
ERROR: COPY force not null available only in CSV mode
COPY x to stdin (format CSV, force_not_null(a));
ERROR: COPY force not null only available using COPY FROM
COPY x to stdout (format TEXT, force_null(a));
ERROR: COPY force null available only in CSV mode
COPY x to stdin (format CSV, force_null(a));
ERROR: COPY force null only available using 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
Expand Down
10 changes: 10 additions & 0 deletions src/test/regress/sql/copy2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ COPY x from stdin (force_null (a), force_null (b));
COPY x from stdin (convert_selectively (a), convert_selectively (b));
COPY x from stdin (encoding 'sql_ascii', encoding 'sql_ascii');

-- incorrect options
COPY x to stdin (format BINARY, delimiter ',');
COPY x to stdin (format BINARY, null 'x');
COPY x to stdin (format TEXT, force_quote(a));
COPY x from stdin (format CSV, force_quote(a));
COPY x to stdout (format TEXT, force_not_null(a));
COPY x to stdin (format CSV, force_not_null(a));
COPY x to stdout (format TEXT, force_null(a));
COPY x to stdin (format CSV, force_null(a));

-- too many columns in column list: should fail
COPY x (a, b, c, d, e, d, c) from stdin;

Expand Down

0 comments on commit 451d116

Please sign in to comment.