@@ -81,6 +81,10 @@ COPY x from stdin (on_error ignore, on_error ignore);
8181ERROR: conflicting or redundant options
8282LINE 1: COPY x from stdin (on_error ignore, on_error ignore);
8383 ^
84+ COPY x from stdin (on_error set_null, on_error ignore);
85+ ERROR: conflicting or redundant options
86+ LINE 1: COPY x from stdin (on_error set_null, on_error ignore);
87+ ^
8488COPY x from stdin (log_verbosity default, log_verbosity verbose);
8589ERROR: conflicting or redundant options
8690LINE 1: COPY x from stdin (log_verbosity default, log_verbosity verb...
@@ -92,6 +96,10 @@ COPY x from stdin (format BINARY, null 'x');
9296ERROR: cannot specify NULL in BINARY mode
9397COPY x from stdin (format BINARY, on_error ignore);
9498ERROR: only ON_ERROR STOP is allowed in BINARY mode
99+ COPY x from stdin (format BINARY, on_error set_null);
100+ ERROR: only ON_ERROR STOP is allowed in BINARY mode
101+ COPY x from stdin (on_error set_null, reject_limit 2);
102+ ERROR: COPY REJECT_LIMIT requires ON_ERROR to be set to IGNORE
95103COPY x from stdin (on_error unsupported);
96104ERROR: COPY ON_ERROR "unsupported" not recognized
97105LINE 1: COPY x from stdin (on_error unsupported);
@@ -124,6 +132,10 @@ COPY x to stdout (format BINARY, on_error unsupported);
124132ERROR: COPY ON_ERROR cannot be used with COPY TO
125133LINE 1: COPY x to stdout (format BINARY, on_error unsupported);
126134 ^
135+ COPY x to stdout (on_error set_null);
136+ ERROR: COPY ON_ERROR cannot be used with COPY TO
137+ LINE 1: COPY x to stdout (on_error set_null);
138+ ^
127139COPY x from stdin (log_verbosity unsupported);
128140ERROR: COPY LOG_VERBOSITY "unsupported" not recognized
129141LINE 1: COPY x from stdin (log_verbosity unsupported);
@@ -776,6 +788,51 @@ CONTEXT: COPY check_ign_err
776788NOTICE: skipping row due to data type incompatibility at line 8 for column "k": "a"
777789CONTEXT: COPY check_ign_err
778790NOTICE: 6 rows were skipped due to data type incompatibility
791+ CREATE DOMAIN d_int_not_null AS INT NOT NULL CHECK(value > 0);
792+ CREATE DOMAIN d_int_positive_maybe_null AS INT CHECK(value > 0);
793+ CREATE TABLE t_on_error_null (a d_int_not_null, b d_int_positive_maybe_null, c INT);
794+ \pset null NULL
795+ --fail, column a cannot set to null value
796+ COPY t_on_error_null FROM STDIN WITH (on_error set_null);
797+ ERROR: domain d_int_not_null does not allow null values
798+ CONTEXT: COPY t_on_error_null, line 1, column a: null input
799+ --fail, column a is domain with not-null constraint
800+ COPY t_on_error_null FROM STDIN WITH (on_error set_null);
801+ ERROR: invalid input value for domain d_int_not_null: "ss"
802+ CONTEXT: COPY t_on_error_null, line 1, column a: "ss"
803+ --fail, column a cannot set to null value
804+ COPY t_on_error_null FROM STDIN WITH (on_error set_null);
805+ ERROR: invalid input value for domain d_int_not_null: "-1"
806+ CONTEXT: COPY t_on_error_null, line 1, column a: "-1"
807+ --fail. less data
808+ COPY t_on_error_null FROM STDIN WITH (delimiter ',', on_error set_null);
809+ ERROR: missing data for column "c"
810+ CONTEXT: COPY t_on_error_null, line 1: "1,1"
811+ --fail. extra data
812+ COPY t_on_error_null FROM STDIN WITH (delimiter ',', on_error set_null);
813+ ERROR: extra data after last expected column
814+ CONTEXT: COPY t_on_error_null, line 1: "1,2,3,4"
815+ --ok
816+ COPY t_on_error_null FROM STDIN WITH (on_error set_null, log_verbosity verbose);
817+ NOTICE: setting to null due to data type incompatibility at line 1 for column "b": "x1"
818+ CONTEXT: COPY t_on_error_null
819+ NOTICE: setting to null due to data type incompatibility at line 1 for column "c": "yx"
820+ CONTEXT: COPY t_on_error_null
821+ NOTICE: setting to null due to data type incompatibility at line 2 for column "b": "zx"
822+ CONTEXT: COPY t_on_error_null
823+ NOTICE: setting to null due to data type incompatibility at line 3 for column "c": "ea"
824+ CONTEXT: COPY t_on_error_null
825+ NOTICE: invalid values in 3 rows were replaced with null due to data type incompatibility
826+ -- check inserted content
827+ select * from t_on_error_null;
828+ a | b | c
829+ ----+------+------
830+ 10 | NULL | NULL
831+ 11 | NULL | 12
832+ 13 | 14 | NULL
833+ (3 rows)
834+
835+ \pset null ''
779836-- tests for on_error option with log_verbosity and null constraint via domain
780837CREATE DOMAIN dcheck_ign_err2 varchar(15) NOT NULL;
781838CREATE TABLE check_ign_err2 (n int, m int[], k int, l dcheck_ign_err2);
@@ -835,6 +892,9 @@ DROP VIEW instead_of_insert_tbl_view;
835892DROP VIEW instead_of_insert_tbl_view_2;
836893DROP FUNCTION fun_instead_of_insert_tbl();
837894DROP TABLE check_ign_err;
895+ DROP TABLE t_on_error_null;
896+ DROP DOMAIN d_int_not_null;
897+ DROP DOMAIN d_int_positive_maybe_null;
838898DROP TABLE check_ign_err2;
839899DROP DOMAIN dcheck_ign_err2;
840900DROP TABLE hard_err;
0 commit comments