使用Case在psql插入时

时间:2016-10-16 02:47:46

标签: sql insert case psql

这是我得到的错误

split

这是我的插入命令,我正在尝试检查当前日期之后是否有3个结束日期,如果有,那么我希望开始日期是最早的日期后5天,否则我的开始日期是2016/05/19

ERROR:  invalid input syntax for type date: "Start_Date"
LINE 8:         'Start_Date'=(CASE WHEN (SELECT COUNT("End_Date") FR...

感谢您

1 个答案:

答案 0 :(得分:0)

您不应该在select中指定列。尝试删除它们:

INSERT INTO Exhibits (
        "Name",
        "Start_Date",
        "End_Date",
        "Description")
SELECT
        'Modern America and the Contemporary World',
        CASE WHEN (
                SELECT COUNT(End_Date) 
                FROM exhibits 
                WHERE End_Date>CURRENT_DATE) >= 3 
             THEN (
                SELECT Min("End_Date")+5 
                FROM exhibits
                WHERE End_Date>CURRENT_DATE) 
             ELSE '2016/05/19' END,
        '2017/01/10',
        'lolololololololol'
;