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

时间:2010-09-02 11:55:14

标签: postgresql

我有以下psql查询,无法理解为什么会出现错误错误:类型为date的输入语法无效:“”

我的查询如下:

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和dsignoff都被定义为日期类型。

1 个答案:

答案 0 :(得分:6)

由于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;