Skip to content

[Bug]: Timezone setting is not correctly reflected on TIMESTAMP columns #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
sh-rp opened this issue Apr 11, 2025 · 0 comments
Open
1 task done

[Bug]: Timezone setting is not correctly reflected on TIMESTAMP columns #1263

sh-rp opened this issue Apr 11, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@sh-rp
Copy link

sh-rp commented Apr 11, 2025

What happened?

When reflecting the table schema, the timezone setting is always set to False on a TIMESTAMP column. It should be set to True for duckdb TIMESTAMPTZ columns. Script to reproduce below:

import os
import duckdb
import os

from sqlalchemy import create_engine, MetaData


if __name__ == "__main__":

    if os.path.exists("input.db"):
        os.remove("input.db")
        print("Removed existing input.db")

    # populate duckdb database with sample data
    conn = duckdb.connect("input.db")
    conn.execute("CREATE SCHEMA raw")
    conn.execute("""
    CREATE TABLE raw.sample_table (
        id INTEGER,
        name TEXT,
        created_at TIMESTAMP,
        created_at_tz TIMESTAMPTZ
    )
    """)

    conn.execute("""
    INSERT INTO raw.sample_table VALUES
    (1, 'Alice', '2024-04-01 10:00:00', '2024-04-01 10:00:00+00'),
    (2, 'Bob', '2024-04-02 11:30:00', '2024-04-02 11:30:00+00'),
    (3, 'Charlie', '2024-04-03 14:15:00', '2024-04-03 14:15:00+00'),
    (4, 'Diana', '2024-04-04 09:45:00', '2024-04-04 09:45:00+00'),
    (5, 'Eve', '2024-04-05 16:20:00', '2024-04-05 16:20:00+00')
    """)

    conn.close()

    engine = create_engine("duckdb:///input.db")
    metadata = MetaData()
    metadata.reflect(bind=engine)

    # Get the Table object
    table = metadata.tables["sample_table"]

    # Get the list of Column objects    
    columns = list(table.columns)
    for c in columns:
        if c.name in ["created_at", "created_at_tz"]:
            print(c.name)
            print(c.type)
            print(c.type.timezone)

DuckDB Engine Version

0.17.0

DuckDB Version

1.2.0

SQLAlchemy Version

Both 1.4 and 2.0.48

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants