finance-dbt/models/dw/dw.dim_date.sql

31 lines
707 B
MySQL
Raw Normal View History

2024-04-12 19:07:47 +08:00
/*
*/
{{
config(
materialized='table',
engine='MergeTree',
order_by='date_id'
)
}}
SELECT
2024-07-23 10:33:41 +08:00
toYYYYMMDD(date) AS date_id,
formatDateTimeInJodaSyntax(date, 'yyyyMMdd') AS date_id_str,
2024-04-12 19:07:47 +08:00
date AS full_date,
toYear(date) AS year,
toUInt8(quarter(date)) AS quarter,
toUInt8(month(date)) AS month,
toUInt8(toDayOfMonth(date)) AS day,
toUInt8(week(date)) AS week_num_of_year,
toUInt8(toDayOfWeek(date)) AS day_num_of_week
FROM (
SELECT
arrayJoin(
arrayMap(
x -> toDate('1990-01-01') + x,
range(toUInt32(dateDiff('day', toDate('1990-01-01'), toDate('2031-01-01'))))
)
) AS date
)
ORDER BY date_id