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

When CAST a TIMESTAMP(x) value AS TIMESTAMP(y), and x > y, the decimal part that exceeds the accuracy will be directly ignored instead of rounding. #11995

Closed
2 tasks done
DDDDDstar opened this issue May 10, 2024 · 2 comments · Fixed by #12011

Comments

@DDDDDstar
Copy link

What happens?

When CAST a TIMESTAMP(x) value AS TIMESTAMP(y), and x > y, the decimal part that exceeds the accuracy will be directly ignored instead of rounding.

To Reproduce

select cast('2024-05-10 11:06:33.846' as timestamp(0)) from t;

The expected result is '2024-05-10 11:06:34', while the actual result is '2024-05-10 11:06:33'.

OS:

macos

DuckDB Version:

v0.10.2

DuckDB Client:

Command line terminal

Full Name:

Shixin Wan

Affiliation:

ApeCloud

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a stable release

Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have
@soerenwolfers
Copy link

soerenwolfers commented May 10, 2024

EDIT: misread the results. PostgreSQL does round up.

This behavior is

  • consistent with DECIMAL:
SELECT
33.846::DECIMAL(4, 2)
┌──────────────────────────────┐
│ CAST(33.846 AS DECIMAL(4,2)) │
│         decimal(4,2)         │
├──────────────────────────────┤
│                        33.84 │
└──────────────────────────────┘

@hawkfish
Copy link
Contributor

Decimal would be a separate issue, but yes PG does round timestamps:

hawkfish=# select cast('2024-05-10 11:06:33.846' as timestamp(0));
      timestamp      
---------------------
 2024-05-10 11:06:34

hawkfish added a commit to hawkfish/duckdb that referenced this issue May 11, 2024
Our casts to lower precision timestamps were not rounding.
This is what PG does sso we should emulate them.

fixes: duckdb#11995
fixes: duckdblabs/duckdb-internal#2015
Mytherin added a commit that referenced this issue May 13, 2024
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