gpt4 book ai didi

postgresql - Postgres : creating DATE Dimension as per Ralph Kimball

转载 作者:行者123 更新时间:2023-11-29 11:55:51 26 4
gpt4 key购买 nike

我是 postgres 和 DW 的新手,我必须设计一个 DATE Dimension,如 book 中给出的那样.我在网上看了很多地方,但到目前为止我没有成功,能否解释一下如何填充 'Fiscal Week'、'Fiscal Month'、'Fiscal Half year'

等字段

谢谢

最佳答案

我猜您想要 10 年的日期维度表,其中包含图 2.4 中显示的所有列(基于 Google Books )。 checkin 文档:

要获得 10 年内的所有天数,您可以这样写:

SELECT generate_series('2001-01-01'::date, '2010-12-31'::date, '1 day') AS day;

SELECT count(*) FROM generate_series('2001-01-01'::date, '2010-12-31'::date, '1 day');
count
-------
3652
(1 row)

根据图2.5建表如:

DROP TABLE IF EXISTS "Date Dimension";
CREATE TABLE "Date Dimension"
(
"Date Key" serial,
"Date" date,
"Full Day Description" text,
"Day Of Week" text,
"Calendar Month" text,
"Calendar Year" integer,
"Fiscal Year Month" text,
"Holiday Indicator" text,
"Weekday Indicator" text
);

插入命令:

INSERT INTO "Date Dimension"
("Date", "Full Day Description", "Day Of Week", "Calendar Month",
"Calendar Year", "Fiscal Year Month", "Holiday Indicator",
"Weekday Indicator")
SELECT
day,
rtrim(to_char(day, 'Month')) || to_char(day, ' DD, YYYY'),
to_char(day, 'Day'),
rtrim(to_char(day, 'Month')),
date_part('year', day),
'F' || to_char(day, 'YYYY-MM'),
'', --omitting (trivial 'Holiday'/'Non-Holiday, but how to get this ??),
CASE
WHEN date_part('isodow', day) IN (6, 7) THEN 'Weekend'
ELSE 'Weekday'
END
FROM
generate_series('2001-01-01'::date, '2010-12-31'::date, '1 day') day;

我希望这能为您提供一些框架和起点。

关于postgresql - Postgres : creating DATE Dimension as per Ralph Kimball,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7098374/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com