Skip to content

Handle dates that underflow differently #595

@JelteF

Description

@JelteF

Description

DuckDB dates can be further into the past than Postgres dates. We should either truncate the date to the lowest possible date that's representable in Postgres, or we should throw an error. Underflowing and returning a date in the future is the worst possible behavior.

This is a query that creates these underflowing dates:

SELECT * FROM duckdb.query($$
    select
        '5877642-06-25 (BC)'::date as date,
        '290309-12-22 (BC) 00:00:00'::timestamp as timestamp,
        '290309-12-22 (BC) 00:00:00'::timestamp_s as timestamp_s,
        '290309-12-22 (BC) 00:00:00'::timestamp_ms as timestamp_ms,
        '290309-12-22 (BC) 00:17:30+00:17'::timestamptz as timestamptz,
$$);
     datetimestamp           │         timestamp_s          │         timestamp_ms         │           timestamptz
───────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼─────────────────────────────────
 5881580-07-14294247-01-10 08:01:49.551616294247-01-10 08:01:49.551616294247-01-10 08:01:49.551616294247-01-10 09:02:19.551616+01
(1 row)

Example of underflowing dates are in this test:

date | 07-14-5881580
timestamp | Sun Jan 10 08:01:49.551616 294247
timestamp_s | Sun Jan 10 08:01:49.551616 294247
timestamp_ms | Sun Jan 10 08:01:49.551616 294247
timestamp_ns | Wed Sep 22 00:00:00 1677
timestamp_tz | Sun Jan 10 00:01:49.551616 294247 PST

Found by #577

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomersincorrect resultBugs that return incorrect datatypesIssues related to type conversions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions