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

Add DATE to dateadd macro #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alittlesliceoftom
Copy link

Fixes #405

tl;dr, helps you avoid errors like:

  Binder Error: Could not choose a best candidate function for the function call "+(STRING_LITERAL, INTERVAL)". In order to select one, please add explicit type casts.        Candidate functions:
        +(DATE, INTERVAL) -> TIMESTAMP
        +(TIME, INTERVAL) -> TIME
        +(TIMESTAMP, INTERVAL) -> TIMESTAMP
        +(TIME WITH TIME ZONE, INTERVAL) -> TIME WITH TIME ZONE
        +(TIMESTAMP WITH TIME ZONE, INTERVAL) -> TIMESTAMP WITH TIME ZONE
        +(INTERVAL, INTERVAL) -> INTERVAL

  LINE 1: /* {"app": "dbt", "dbt_version": "1.7.9", "profile_...

@alittlesliceoftom
Copy link
Author

@alittlesliceoftom
Copy link
Author

I didn't have time to setup integration tests, but tested the updated macro locally, and 'correct' example now works:

SELECT
{{ dateadd(datepart="month", interval=1, from_date_or_timestamp="'2021-08-12'") }} AS period_of_load

@jwills
Copy link
Collaborator

jwills commented Jun 19, 2024

yeah I'm surprised this didn't break on the regular unit tests-- like, does this not work anymore and I missed it? https://github.com/dbt-labs/dbt-adapters/blob/main/dbt-tests-adapter/dbt/tests/adapter/utils/fixture_dateadd.py

@alittlesliceoftom
Copy link
Author

alittlesliceoftom commented Jun 19, 2024

Possibly those are more explicit strings? So inference can work?

@jwills
Copy link
Collaborator

jwills commented Jun 19, 2024

My concern here is what happens if I pass in a TIMESTAMP instead of a string or a DATE? Or a string that should be cast as a TIMESTAMP instead?

@alittlesliceoftom
Copy link
Author

Yeh... Interestingly in DuckDb the dateadd operations seem to expect the coder to know and set the type ahead of time in the statement?
https://duckdb.org/docs/sql/functions/interval

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 this pull request may close these issues.

Duck Db support of DATEADD from Core
2 participants