postgresql 错误:类型日期的输入语法无效:“”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3626821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-20 00:16:27  来源:igfitidea点击:

ERROR: invalid input syntax for type date: ""

postgresql

提问by Elitmiar

I have the following psql query and can't understand why I get error ERROR: invalid input syntax for type date: "".

我有以下 psql 查询,但不明白为什么我收到错误ERROR: invalid input syntax for type date: ""

My query looks as follows:

我的查询如下所示:

SELECT count(*) FROM campaigns 
WHERE 
    dstart >= '2010-09-02' AND 
    dend <= '2010-09-02' AND 
    status != 'S' AND 
    status != 'C' AND 
    status != 'E' AND 
    (dsignoff <> '' AND dsignoff is not null) AND 
    (dstart <> '' AND dstart is not null) AND 
    (dend <> '' AND dend is not null) AND 
    clientid=20005294;

dstart,dend and dsignoff are all defined as date types.

dstart、dend 和 dsignoff 都定义为日期类型。

回答by Alex Reitbort

Since dstart,dend and dsignoff are defined as date, they can not be compared to string that represents invalid date (''). Try this:

由于 dstart、dend 和 dsignoff 被定义为日期,因此无法将它们与表示无效日期 ('') 的字符串进行比较。尝试这个:

SELECT count(*) FROM campaigns 
WHERE 
    dstart >= '2010-09-02' AND 
    dend <= '2010-09-02' AND 
    status != 'S' AND 
    status != 'C' AND 
    status != 'E' AND 
    (dsignoff is not null) AND 
    (dstart is not null) AND 
    (dend is not null) AND 
    clientid=20005294;