File: test_csv_timestamp_tz.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 (114 lines) | stat: -rw-r--r-- 3,514 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
# name: test/sql/copy/csv/test_csv_timestamp_tz.test
# description: Test CSV with timestamp_tz and timestampformat
# group: [csv]

statement ok
pragma enable_verification


statement error
copy (
select '2021-05-25 04:55:03.382494 UTC'::timestamp as ts, '2021-05-25 04:55:03.382494 UTC'::timestamptz as tstz
) to '{TEMP_DIR}/timestamps.csv' ( timestampformat '%A');
----
No function matches the given name and argument types

require icu

require no_extension_autoloading "FIXME: In CSV value conversion we don't autoload ICU"

statement ok
SET TimeZone='UTC'

# If we set to timestamptz it works
query II
FROM read_csv('{DATA_DIR}/csv/timestamp_timezone.csv', columns = {'time':'timestamptz', 'description':'varchar'})
----
2020-01-01 00:00:00+00	midnight local
2020-01-01 08:00:00+00	midnight in San Francisco
2020-01-01 00:00:00+00	midnight UTC +00
2020-01-01 00:00:00+00	midnight UTC Z
2019-12-31 16:00:00+00	midnight in Taipei
2019-12-31 18:30:00+00	Asia/Kolkata
2019-12-31 10:15:00+00	Pacific/Chatham
2020-01-01 03:30:00+00	Canada/Newfoundland

query II
FROM read_csv('{DATA_DIR}/csv/timestamp_timezone.csv', auto_type_candidates = ['BOOLEAN', 'BIGINT', 'DOUBLE', 'TIME', 'DATE', 'TIMESTAMP','TIMESTAMPTZ', 'VARCHAR'])
----
2020-01-01 00:00:00+00	midnight local
2020-01-01 08:00:00+00	midnight in San Francisco
2020-01-01 00:00:00+00	midnight UTC +00
2020-01-01 00:00:00+00	midnight UTC Z
2019-12-31 16:00:00+00	midnight in Taipei
2019-12-31 18:30:00+00	Asia/Kolkata
2019-12-31 10:15:00+00	Pacific/Chatham
2020-01-01 03:30:00+00	Canada/Newfoundland


query II
FROM read_csv('{DATA_DIR}/csv/timestamp_timezone.csv', auto_type_candidates = ['BOOLEAN', 'BIGINT', 'DOUBLE', 'TIME', 'DATE', 'TIMESTAMPTZ', 'VARCHAR'])
----
2020-01-01 00:00:00+00	midnight local
2020-01-01 08:00:00+00	midnight in San Francisco
2020-01-01 00:00:00+00	midnight UTC +00
2020-01-01 00:00:00+00	midnight UTC Z
2019-12-31 16:00:00+00	midnight in Taipei
2019-12-31 18:30:00+00	Asia/Kolkata
2019-12-31 10:15:00+00	Pacific/Chatham
2020-01-01 03:30:00+00	Canada/Newfoundland

query I
SELECT columns FROM sniff_csv('{DATA_DIR}/csv/timestamp_timezone.csv')
----
[{'name': time, 'type': TIMESTAMP WITH TIME ZONE}, {'name': description, 'type': VARCHAR}]

query II
FROM '{DATA_DIR}/csv/timestamp_timezone.csv'
----
2020-01-01 00:00:00+00	midnight local
2020-01-01 08:00:00+00	midnight in San Francisco
2020-01-01 00:00:00+00	midnight UTC +00
2020-01-01 00:00:00+00	midnight UTC Z
2019-12-31 16:00:00+00	midnight in Taipei
2019-12-31 18:30:00+00	Asia/Kolkata
2019-12-31 10:15:00+00	Pacific/Chatham
2020-01-01 03:30:00+00	Canada/Newfoundland


query I
SELECT columns FROM sniff_csv('{DATA_DIR}/csv/timestamp_with_tz.csv')
----
[{'name': id, 'type': BIGINT}, {'name': timestamps, 'type': TIMESTAMP WITH TIME ZONE}]

query II
FROM '{DATA_DIR}/csv/timestamp_with_tz.csv'
----
1	2021-05-25 04:55:03.382494+00
2	2021-05-25 09:55:03.382494+00

# Test over vector size timestamp
statement ok
create table t as SELECT '1; 2020-01-01 00:00:00+00' as ts from range (10000)

statement ok
copy t to '{TEMP_DIR}/timetz.csv'

query I
SELECT columns FROM sniff_csv('{TEMP_DIR}/timetz.csv')
----
[{'name': column0, 'type': BIGINT}, {'name': column1, 'type': TIMESTAMP WITH TIME ZONE}]

statement ok
insert into t values ('2; thisisastring')

statement ok
copy t to '{TEMP_DIR}/timetz_2.csv'

query I
SELECT columns FROM sniff_csv('{TEMP_DIR}/timetz_2.csv')
----
[{'name': column0, 'type': BIGINT}, {'name': column1, 'type': VARCHAR}]

statement ok
drop table t;