File: test_copy_null.test

package info (click to toggle)
duckdb 1.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 558
file content (176 lines) | stat: -rw-r--r-- 4,180 bytes parent folder | download | duplicates (3)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# name: test/sql/copy/csv/test_copy_null.test
# description: Test NULL option of copy statement
# group: [csv]

statement ok
PRAGMA enable_verification


# generate CSV file with default delimiter
# create a table
statement ok
CREATE TABLE test_null_option (col_a INTEGER, col_b VARCHAR(10), col_c VARCHAR(10), col_d VARCHAR(10), col_e VARCHAR);

# test COPY ... FROM ...
# implicitly using default NULL value
query I
COPY test_null_option FROM '{DATA_DIR}/csv/test/test_null_option.csv' (NULL 'NULL');
----
3

query ITTTT
SELECT * FROM test_null_option ORDER BY 1 LIMIT 3;
----
0	(empty)	test	null	NULL
1	(empty)	test	null	NULL
2	(empty)	test	null	NULL

statement ok
DELETE FROM test_null_option;

# explicitly using default NULL value
query I
COPY test_null_option FROM '{DATA_DIR}/csv/test/test_null_option.csv' (NULL '');
----
3

query ITTTT
SELECT * FROM test_null_option ORDER BY 1 LIMIT 3;
----
0	NULL	test	null	NULL
1	NULL	test	null	NULL
2	NULL	test	null	NULL

statement ok
DELETE FROM test_null_option;

# make sure a quoted null string is not interpreted as a null value
query I
COPY test_null_option FROM '{DATA_DIR}/csv/test/test_null_option.csv' (NULL 'test');
----
3

query ITTTT
SELECT * FROM test_null_option ORDER BY 1 LIMIT 3;
----
0	(empty)	NULL	null	NULL
1	(empty)	NULL	null	NULL
2	(empty)	NULL	null	NULL

statement ok
DELETE FROM test_null_option;

# setting specific NULL value
query I
COPY test_null_option FROM '{DATA_DIR}/csv/test/test_null_option.csv' (NULL 'null');
----
3

query ITTTT
SELECT * FROM test_null_option ORDER BY 1 LIMIT 3;
----
0	(empty)	test	NULL	NULL
1	(empty)	test	NULL	NULL
2	(empty)	test	NULL	NULL

# invalid parameter type
statement error
COPY test_null_option FROM '{DATA_DIR}/csv/test/test_null_option.csv' (NULL null);
----
NULL is not supported

# delimiter must not appear in the NULL specification
statement error
COPY test_null_option FROM '{DATA_DIR}/csv/test/test_null_option.csv' (NULL 'null,', DELIMITER ',');
----
DELIMITER must not appear in the NULL specification and vice versa

statement error
COPY test_null_option FROM '{DATA_DIR}/csv/test/test_null_option.csv' (DELIMITER 'null', NULL 'null');
----
It was not possible to automatically detect the CSV parsing dialect

statement error
COPY test_null_option FROM '{DATA_DIR}/csv/test/test_null_option.csv' (DELIMITER 'null', NULL 'nu');
----
It was not possible to automatically detect the CSV parsing dialect

# no parameter type
statement error
COPY test_null_option FROM '{DATA_DIR}/csv/test/test_null_option.csv' (NULL);
----
CSV Reader function option null requires a non-empty list of possible null strings (varchar) as input

# empty integer column with non-default NULL string
statement ok
CREATE TABLE test_null_option_2 (col_a INTEGER, col_b INTEGER, col_c VARCHAR(10), col_d VARCHAR(10));

statement error
COPY test_null_option_2 FROM '{DATA_DIR}/csv/test/test_null_option.csv' (NULL 'null');
----
It was not possible to automatically detect the CSV parsing dialect

# test COPY ... TO ...
# implicitly using default NULL value
query I
COPY test_null_option TO '{TEMP_DIR}/test_null_option_2.csv';
----
3

statement ok
DELETE FROM test_null_option;

query I
COPY test_null_option FROM '{TEMP_DIR}/test_null_option_2.csv';
----
3

query ITTTT
SELECT * FROM test_null_option ORDER BY 1 LIMIT 3;
----
0	NULL	test	NULL	NULL
1	NULL	test	NULL	NULL
2	NULL	test	NULL	NULL

# explicitly using default NULL value
query I
COPY test_null_option TO '{TEMP_DIR}/test_null_option_3.csv' (NULL '');
----
3

statement ok
DELETE FROM test_null_option;

query I
COPY test_null_option FROM '{TEMP_DIR}/test_null_option_3.csv' (NULL '');
----
3

query ITTTT
SELECT * FROM test_null_option ORDER BY 1 LIMIT 3;
----
0	NULL	test	NULL	NULL
1	NULL	test	NULL	NULL
2	NULL	test	NULL	NULL

# setting specific NULL value
query I
COPY test_null_option TO '{TEMP_DIR}/test_null_option_4.csv' (NULL 'null');
----
3

statement ok
DELETE FROM test_null_option;

query I
COPY test_null_option FROM '{TEMP_DIR}/test_null_option_4.csv' (NULL 'null');
----
3

query ITTTT
SELECT * FROM test_null_option ORDER BY 1 LIMIT 3;
----
0	NULL	test	NULL	NULL
1	NULL	test	NULL	NULL
2	NULL	test	NULL	NULL