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

wrong results with extract(second from <interval>) #2586

Closed
1 task
gregrahn opened this issue Nov 12, 2021 · 1 comment · Fixed by #2639
Closed
1 task

wrong results with extract(second from <interval>) #2586

gregrahn opened this issue Nov 12, 2021 · 1 comment · Fixed by #2639
Assignees

Comments

@gregrahn
Copy link

gregrahn commented Nov 12, 2021

What happens?

When extracting the seconds component from an interval it returns the entire value in seconds. This is what extract(epoch from <interval>) should return.

To Reproduce

D select extract( second from interval '2 hours 2 minutes 10 seconds' ) as value_should_be_10;
┌────────────────────┐
│ value_should_be_10 │
├────────────────────┤
│ 7330               │
└────────────────────┘

D select extract( epoch from interval '2 hours 2 minutes 10 seconds' ) as value_should_be_7330;
┌──────────────────────┐
│ value_should_be_7330 │
├──────────────────────┤
│ 7330                 │
└──────────────────────┘

Environment (please complete the following information):

  • OS: macOS 11.5.2
  • DuckDB Version: 0.3.0
  • DuckDB Client: duckdb-cli

Before Submitting

  • Have you tried this on the latest master branch?

No, but it's also incorrect in the test file here as well
https://github.com/duckdb/duckdb/blob/master/test/sql/function/interval/test_extract.test#L126

PostgreSQL 13.2

greg.rahn=# SELECT i, EXTRACT(second FROM i) FROM intervals;
       i       | date_part
---------------+-----------
 2 years       |         0
 1 year 4 mons |         0
 42 days       |         0
 00:34:26.3434 |   26.3434
 [NULL]        |    [NULL]

DuckDB

D SELECT i, EXTRACT(second FROM i) FROM intervals;
┌─────────────────┬──────────────────────┐
│        i        │ date_part(second, i) │
├─────────────────┼──────────────────────┤
│ 2 years         │ 0                    │
│ 1 year 4 months │ 0                    │
│ 42 days         │ 0                    │
│ 00:34:26.3434   │ 2066                 │ <<< should be 20.3434
│                 │                      │
└─────────────────┴──────────────────────┘
@Mytherin Mytherin self-assigned this Nov 19, 2021
@Mytherin
Copy link
Collaborator

Thanks for the report! Going to have a look at this.

Mytherin added a commit to Mytherin/duckdb that referenced this issue Nov 19, 2021
…rvals, and sort of follow Postgres in date_part for epoch
Mytherin added a commit that referenced this issue Nov 19, 2021
Fix #2586: correct semantics for extract(second, ...) from intervals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants