1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
# name: test/sql/copy/csv/test_force_not_null.test
# description: Test force_not_null
# group: [csv]
statement ok
PRAGMA enable_verification
statement ok
CREATE TABLE test (col_a INTEGER, col_b VARCHAR(10), col_c VARCHAR(10));
# test if null value is correctly converted into string
query I
COPY test FROM '{DATA_DIR}/csv/test/force_not_null.csv' (FORCE_NOT_NULL (col_b), NULL 'test', HEADER 0,allow_quoted_nulls false );
----
3
query ITT
SELECT * FROM test ORDER BY 1;
----
0 (empty) NULL
1 (empty) NULL
8 test tea
statement ok
DELETE FROM test;
# test if null value is correctly converted into string if explicit columns are used
query I
COPY test (col_a, col_b, col_c) FROM '{DATA_DIR}/csv/test/force_not_null.csv' (FORCE_NOT_NULL (col_b), NULL 'test', HEADER 0, allow_quoted_nulls false);
----
3
query ITT
SELECT * FROM test ORDER BY 1;
----
0 (empty) NULL
1 (empty) NULL
8 test tea
# FORCE_NOT_NULL is only supported in COPY ... FROM ...
statement error
COPY test TO '{DATA_DIR}/csv/test/force_not_null.csv' (FORCE_NOT_NULL (col_b), NULL 'test', HEADER 0);
----
Option "FORCE_NOT_NULL" is not supported for writing - only for reading
# FORCE_NOT_NULL must not be empty and must have the correct parameter type
statement error
COPY test FROM '{DATA_DIR}/csv/test/force_not_null.csv' (FORCE_NOT_NULL, NULL 'test');
----
"force_not_null" expects a column list or * as parameter
statement error
COPY test FROM '{DATA_DIR}/csv/test/force_not_null.csv' (FORCE_NOT_NULL 42, NULL 'test');
----
"force_not_null" expected to find 42, but it was not found in the table
# test using a column in FORCE_NOT_NULL that is not set as output, but that is a column of the table
statement error
COPY test (col_b, col_a) FROM '{DATA_DIR}/csv/test/force_not_null_reordered.csv' (FORCE_NOT_NULL (col_c, col_b));
----
"force_not_null" expected to find col_c, but it was not found in the table
# test using a column in FORCE_NOT_NULL that is not a column of the table
statement error
COPY test FROM '{DATA_DIR}/csv/test/force_not_null_reordered.csv' (FORCE_NOT_NULL (col_c, col_d));
----
"force_not_null" expected to find col_d, but it was not found in the table
# FORCE_NOT_NULL fails on integer columns with NULL values, but only if there are null values
query I
COPY test FROM '{DATA_DIR}/csv/test/force_not_null.csv' (FORCE_NOT_NULL (col_a), HEADER 0);
----
3
statement error
COPY test FROM '{DATA_DIR}/csv/test/force_not_null_inull.csv' (FORCE_NOT_NULL (col_a), HEADER 0);
----
Error when converting column "col_a".
|