我想在外部混合每個位置的時區信息過濾具有時間戳的行不帶時區值。Jooq notation with multiple arrays
我怎樣才能在Jooq表達這種SQL(PostgreSQL系統)片斷
WITH
now(locaton, value) AS (
SELECT
*
FROM unnest(
ARRAY[1,2]::BIGINT[],
ARRAY['2017-05-28 09:30','2017-05-28 10:30']::TIMESTAMP[])
)
SELECT *
FROM now;
不太理想,但仍然工作片段是:
WITH
now(locaton, value) AS (
SELECT
unnest(ARRAY[1,2]::BIGINT[]) as location,
unnest(ARRAY['2017-05-28 09:30','2017-05-28 10:30']::TIMESTAMP[]) as value
)
SELECT *
FROM now;
可能更正確(已被Add support for the SQL Standard WITH ORDINALITY clause #5799)
SELECT location, value
FROM
unnest(ARRAY[1,2]::BIGINT[]) WITH ORDINALITY as location
JOIN unnest(ARRAY['2017-05-28 09:30','2017-05-28 10:30']::TIMESTAMP[]) WITH ORDINALITY as value
USING (ordinality);
獲取
location | value
------------+---------------------
1 | 2017-05-28 09:30:00
2 | 2017-05-28 10:30:00
(2 rows)
哦,使用'WITH ORDINALITY'非常好的解決方案。也許這個問題應該得到更高的優先權。 –