gpt4 book ai didi

sql - Postgres - 将 TSTZRANGE 分成两列

转载 作者:行者123 更新时间:2023-11-29 12:29:43 25 4
gpt4 key购买 nike

我正在使用 PostgreSQL 9.4我在一个名为 timerange 的表中有一个列,我想编写一个 SELECT 查询,它将在两个单独的列 time_start 中返回时间范围time_end.我试图像处理数组一样处理它,但它不起作用:

select *, timerange[0] as t_start from schedules;

当前表:

| id |                    timerange                        |  
|----|-----------------------------------------------------|
| 1 | ["2017-05-05 19:00:00+02","2017-05-05 21:00:00+02") |
| 2 | ["2017-05-05 19:00:00+02","2017-05-05 21:00:00+02") |

所需的表:

| id |        time_start        |       time_end           | 
|----|--------------------------|--------------------------|
| 1 | "2017-05-05 19:00:00+02" | "2017-05-05 21:00:00+02" |
| 2 | "2017-05-05 19:00:00+02" | "2017-05-05 21:00:00+02" |

最佳答案

Use lower()upper()

像这样:

SELECT lower(tsrng) AS start, upper(tsrng) AS end
FROM (
SELECT tstzrange('2017-05-05 12:00:05', '2017-05-05 16:00:05', '[)') AS tsrng
) sub;

或者你的例子:

select *, lower(timerange) as t_start, upper(timerange) as t_end from schedules;

关于sql - Postgres - 将 TSTZRANGE 分成两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43806314/

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