Skip to content

Commit b084162

Browse files
committed
Fix duckdb#105: when loading TIMESTAMP_TZ columns from MySQL - they are send over in UTC already, so we should not reinterpret these as being in the users' timezone
1 parent d0c56ab commit b084162

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/mysql_scanner.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ static void MySQLScan(ClientContext &context, TableFunctionInput &data, DataChun
148148
// '\1')
149149
CastBoolFromMySQL(context, gstate.varchar_chunk.data[c], output.data[c], r);
150150
break;
151+
case LogicalTypeId::TIMESTAMP_TZ: {
152+
string error;
153+
VectorOperations::DefaultTryCast(gstate.varchar_chunk.data[c], output.data[c], r, &error);
154+
break;
155+
}
151156
default: {
152157
string error;
153158
VectorOperations::TryCast(context, gstate.varchar_chunk.data[c], output.data[c], r, &error);

test/sql/attach_timestamp_tz_roundtrip.test

Whitespace-only changes.

test/sql/attach_timezone_insert.test

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ require mysql_scanner
66

77
require-env MYSQL_TEST_DATABASE_AVAILABLE
88

9+
require icu
10+
911
statement ok
1012
ATTACH 'host=localhost user=root port=0 database=mysqlscanner' AS s (TYPE MYSQL_SCANNER)
1113

1214
statement ok
1315
USE s
1416

17+
statement ok
18+
SET TimeZone='UTC'
19+
1520
statement ok
1621
CREATE OR REPLACE TABLE timestamp_with_tz_tbl(ts TIMESTAMP WITH TIME ZONE);
1722

@@ -22,3 +27,36 @@ query I
2227
SELECT * FROM timestamp_with_tz_tbl
2328
----
2429
2000-01-01 12:12:12+00
30+
31+
statement ok
32+
INSERT INTO timestamp_with_tz_tbl VALUES (TIMESTAMPTZ '2001-01-01 12:12:12+04:00')
33+
34+
query I
35+
SELECT * FROM timestamp_with_tz_tbl
36+
----
37+
2000-01-01 12:12:12+00
38+
2001-01-01 08:12:12+00
39+
40+
statement ok
41+
SET TimeZone='EST'
42+
43+
query I
44+
SELECT * FROM timestamp_with_tz_tbl
45+
----
46+
2000-01-01 07:12:12-05
47+
2001-01-01 03:12:12-05
48+
49+
statement ok
50+
create or replace table new_tbl(t timestamp with time zone);
51+
52+
statement ok
53+
INSERT INTO new_tbl SELECT * FROM timestamp_with_tz_tbl
54+
55+
statement ok
56+
SET TimeZone='UTC'
57+
58+
query I
59+
SELECT * FROM new_tbl
60+
----
61+
2000-01-01 12:12:12+00
62+
2001-01-01 08:12:12+00

0 commit comments

Comments
 (0)