Skip to content

mysql extension treats "timestamp" column as "timestamp with timezone", causing data errors #105

Closed
@marhar

Description

@marhar

Copying a mysql TIMEZONE column changes the value.

  • DuckDB treats "timestamp" columns as "timestamp with timezone".
  • This causes incorrect operation when comparing timestamp columns when not in UTC-0 timezone.
  • my timezone: UTC-8

Expected results:

Copying a timestamp column in DuckDB does not change the timestamp value.

Actual Results:

Copying a timestamp column in DuckDB changes the timestamp value.

Execute in mysql:

-- $ mysql -u root -D testdb
create table a(t timestamp(6));
create table b(t timestamp(6));
insert into a values(now(6));
describe a;
-- +-------+--------------+------+-----+---------+-------+
-- | Field | Type         | Null | Key | Default | Extra |
-- +-------+--------------+------+-----+---------+-------+
-- | t     | timestamp(6) | YES  |     | NULL    |       |
-- +-------+--------------+------+-----+---------+-------+

Execute in duckdb:

-- set timezone='UTC'; -- note: my timezone is +8
ATTACH 'host=localhost user=root port=0 database=testdb' AS my(TYPE MYSQL);

select * from my.a;
insert into my.b select * from my.a;
select * from my.b;

describe my.a;

Execution Results:

select * from my.a;
┌───────────────────────────────┐
│               t               │
│   timestamp with time zone    │
├───────────────────────────────┤
│ 2024-12-16 09:40:40.396764-08 │
└───────────────────────────────┘
select * from my.b;
┌───────────────────────────────┐
│               t               │
│   timestamp with time zone    │
├───────────────────────────────┤
│ 2024-12-16 17:40:40.396764-08 │ <<<<<<<< value is offset, should be same as above
└───────────────────────────────┘

describe my.a;
┌─────────────┬──────────────────────────┬─────────┬─────────┬─────────┬─────────┐
│ column_name │       column_type        │  null   │   key   │ default │  extra  │
│   varchar   │         varchar          │ varchar │ varchar │ varchar │ varchar │
├─────────────┼──────────────────────────┼─────────┼─────────┼─────────┼─────────┤
│ t           │ TIMESTAMP WITH TIME ZONE │ YES     │  <<<<<< should be simple TIMESTAMP
└─────────────┴──────────────────────────┴─────────┴─────────┴─────────┴─────────┘

Note that the data error also shows up in MySQL:

mysql> select * from a;
+----------------------------+
| t                          |
+----------------------------+
| 2024-12-16 09:40:40.396764 |
+----------------------------+

mysql> select * from b;
+----------------------------+
| t                          |
+----------------------------+
| 2024-12-16 17:40:40.396764 | <<<< should be same as above
+----------------------------+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions