Skip to content
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

Weird equality comparison when TIMESTAMP_NS stored in tables, subqueries and CTEs is casted to DATE #11377

Closed
1 task done
Matts966 opened this issue Mar 27, 2024 · 1 comment · Fixed by #11392
Closed
1 task done

Comments

@Matts966
Copy link

Matts966 commented Mar 27, 2024

What happens?

  • DATE values converted from TIMESTAMP_NS stored in tables, subqueries, and CTEs are different from DATE literal even though the values look the same.
  • This does not happen when TIMESTAMP_NS values are literal instantiated in the clause.
  • This is one of the realistic usages of DuckDB because Pandas DateTime values are converted to TIMESTAMP_NS and comparing date values of timestamps stored in tables is natural. I found this case when filtering a dataset with a date.
WITH t AS (
    SELECT
        '2020/09/13 00:30:00'::TIMESTAMP_NS AS a,
        a::DATE as c,
)
SELECT
    version(),
    '2020/09/13 00:30:00'::TIMESTAMP_NS AS b,
    a::DATE = DATE '2020/09/13',
    b::DATE = DATE '2020/09/13',
    c = DATE '2020/09/13',
    a::DATE, b::DATE, c, DATE '2020/09/13',
FROM t;

returns

version() b (CAST(a AS DATE) = CAST('2020/09/13' AS DATE)) (CAST(b AS DATE) = CAST('2020/09/13' AS DATE)) (c = CAST('2020/09/13' AS DATE)) CAST(a AS DATE) CAST(b AS DATE) c CAST('2020/09/13' AS DATE)
v0.10.1 2020-09-13 00:30:00 False True True 2020-09-13 2020-09-13 2020-09-13 2020-09-13

To Reproduce

Use the SQL above

OS:

Linux x86

DuckDB Version:

v0.10.1

DuckDB Client:

Python

Full Name:

Masahiro Matsui

Affiliation:

Treasure Data

Have you tried this on the latest nightly build?

I have tested with a release build (and could not test with a nightly build)

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • Yes, I have
@szarnyasg
Copy link
Collaborator

Thanks, we'll look into this

hawkfish pushed a commit to hawkfish/duckdb that referenced this issue Mar 27, 2024
All casts from timestamp types to DATE are not invertible.

fixes: duckdb#11377
fixes: duckdblabs/duckdb-internal#1697
Mytherin added a commit that referenced this issue Mar 28, 2024
ccfelius pushed a commit to ccfelius/duckdb that referenced this issue Apr 6, 2024
All casts from timestamp types to DATE are not invertible.

fixes: duckdb#11377
fixes: duckdblabs/duckdb-internal#1697
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants