dblink不接受Postgressql的日期格式

时间:2019-04-11 05:07:39

标签: postgresql dblink

我正在使用dblink从其他数据库中提取数据,但是当我放置日期条件时,它显示在错误下方

ERROR:  syntax error at or near "2019"
LINE 5:   where date(l.create_date)='2019-01-01'') 
                                     ^
SQL state: 42601
Character: 562
select cus.* into cus_details from dblink('dbname=dbname user=admin password=admin123',
'select l.id,l.create_date,l.write_date,b.campaign
        from rb_lead l
         left join rb_campaign b on l.team=b.id 
        where date(l.create_date)='2019-01-01'')
as cus (id integer,create_date timestamp without time zone,write_date timestamp without time zone,campaign integer)

1 个答案:

答案 0 :(得分:1)

带引号的字符串中有引号。

select cus.* into cus_details
from dblink(
    'dbname=dbname user=admin password=admin123',
    'select ... where date(l.create_date)='2019-01-01''
)
                                          ^

您需要通过将2019-01-01周围的引号加倍来对其进行转义。

select cus.* into cus_details
from dblink(
    'dbname=dbname user=admin password=admin123',
    'select ... where date(l.create_date)=''2019-01-01'''
)