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

Snowflake / dbt DAY_OF_WEEK incorrect #120

Open
tuday2 opened this issue Jan 10, 2024 · 0 comments
Open

Snowflake / dbt DAY_OF_WEEK incorrect #120

tuday2 opened this issue Jan 10, 2024 · 0 comments

Comments

@tuday2
Copy link

tuday2 commented Jan 10, 2024

I am trying to create a date dimension with Snowflake. I need the week to start on Sunday.

I finally figured out I needed to change the Snowflake "WEEK_START" setting to 7 (Sunday) to get week numbers to accurately reflect a Sunday start.

Now the issue is with Day of Week. With Snowflake "WEEK_START" set to 7, here is the output of dbt-date for iso/non-iso:
Sunday = 7 (DAY_OF_WEEK_ISO)
Sunday = 2 (DAY_OF_WEEK)

I need Sunday to be 1. Looking at the code in DAY_OF_WEEK i stumbled upon this line below that is adding + 1 (did Snowflake use to return 0?) -- this is causing Sunday to be 2 in DAY_OF_WEEK which is not correct.

https://github.com/calogica/dbt-date/blob/df2f567efacd1e0074f86600812213f5d79c1b1b/macros/calendar_date/day_of_week.sql#L30C1-L30C62

If I run the snowflake functions directly for 01/02/2022, a Sunday, they are correct:
SELECT DAYOFWEEK(date'2022-01-02') = 1
SELECT DAYOFWEEKISO(date'2022-01-02') = 7

So my guess is that +1 in the DAYOFWEEK is not needed anymore.

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

No branches or pull requests

1 participant