File: test_force_quote.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 (96 lines) | stat: -rw-r--r-- 2,465 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
# name: test/sql/copy/csv/test_force_quote.test
# description: Test force_quote
# group: [csv]

statement ok
PRAGMA enable_verification


# create a table
statement ok
CREATE TABLE test (col_a INTEGER, col_b VARCHAR(10), col_c VARCHAR(10));

query I
COPY test FROM '{DATA_DIR}/csv/test/force_quote.csv' (HEADER 0);
----
3

# test FORCE_QUOTE *
query I
COPY test TO '{TEMP_DIR}/test_star.csv' (FORCE_QUOTE *, HEADER 0);
----
3

# test FORCE_QUOTE with specific columns and non-default quote character and non-default null character
query I
COPY test TO '{TEMP_DIR}/test_chosen_columns.csv' (FORCE_QUOTE (col_a, col_c), QUOTE 't', NULL 'ea');
----
3

# verify that we can load the results back in
statement ok
CREATE TABLE test2 (col_a INTEGER, col_b VARCHAR(10), col_c VARCHAR(10));

query I
COPY test2 FROM '{TEMP_DIR}/test_chosen_columns.csv' (QUOTE 't', NULL 'ea');
----
3

query ITT
SELECT * FROM test2
----
8	test	tea
0	NULL	test
1	NULL	test

# test FORCE_QUOTE with reordered columns
query I
COPY test (col_b, col_c, col_a) TO '{TEMP_DIR}/test_reorder.csv' (FORCE_QUOTE (col_c, col_b), NULL 'test');
----
3

statement ok
CREATE TABLE test3 (col_a INTEGER, col_b VARCHAR(10), col_c VARCHAR(10));

query I
COPY test3(col_b, col_c, col_a) FROM '{TEMP_DIR}/test_reorder.csv' (NULL 'test');
----
3

query ITT
SELECT * FROM test2
----
8	test	tea
0	NULL	test
1	NULL	test


# test using a column in FORCE_QUOTE that is not set as output, but that is a column of the table
statement error
COPY test (col_b, col_a) TO '{TEMP_DIR}/test_reorder.csv' (FORCE_QUOTE (col_c, col_b));
----
"force_quote" expected to find col_c, but it was not found in the table

# test using a column in FORCE_QUOTE that is not a column of the table
statement error
COPY test TO '{TEMP_DIR}/test_reorder.csv' (FORCE_QUOTE (col_c, col_d));
----
"force_quote" expected to find col_d, but it was not found in the table

# FORCE_QUOTE is only supported in COPY ... TO ...
statement error
COPY test FROM '{TEMP_DIR}/test_reorder.csv' (FORCE_QUOTE (col_c, col_d));
----
Option "FORCE_QUOTE" is not supported for reading - only for writing

# FORCE_QUOTE must not be empty and must have the correct parameter type
statement error
COPY test TO '{TEMP_DIR}/test_reorder.csv' (FORCE_QUOTE);
----
"force_quote" expects a column list or * as parameter

statement error
COPY test TO '{TEMP_DIR}/test_reorder.csv' (FORCE_QUOTE 42);
----
"force_quote" expected to find 42, but it was not found in the table