首页 > 解决方案 > 将 SQL Server / C# 查询转换为 PostgreSQL

问题描述

我是 postgres 的新手,我遇到了一个问题,但我在这里找到了解决方案: https ://stackoverflow.com/a/31841098/15663795

但问题是这个查询不在 PostgreSQL 中。有人可以帮助转换此查询吗?

with [TimeSlotCTE] as
(
    -- Base case: the first appointment slot of the day.
    select 
        [From] = @StartTime, 
        [To] = dateadd(minute, @DesiredLength, @StartTime)

    union all

    -- Recursive case: create a subsequent appointment slot as long as doing so won't
    -- take us past the office's closing time.
    select
        dateadd(minute, @Interval, [From]),
        dateadd(minute, @Interval, [To])
    from
        [TimeSlotCTE]
    where
        dateadd(minute, @Interval, [To]) <= @EndTime
)

我试过这个:

WITH TIMESLOTS AS
                (SELECT * FROM (VALUES('09:00','09:30')) BASE("start","end")
                    UNION ALL SELECT "start" + interval '30 minutes',
                        "end" + interval '30 minutes')
SELECT *
FROM TIMESLOTS;

但它显示以下错误 column "start" does not exist

标签: sqlpostgresql

解决方案


推荐阅读