在我的 postgresql 的 shell 中,将变量的值设置为“2023-11-01”:
\set date '2023-11-01'
叫它 :
\echo :'date'
'2023-11-01'
\echo :date
2023-11-01
在选择中使用它
select * from quote where date=:'date';
当日期为时2023-11-01
,它输出报价中的所有记录,我想将所有记录复制到/tmp/records.csv
:
\copy (select * from quote where date=:'date') to '/tmp/result.csv'
ERROR: syntax error at or near ":"
LINE 1: COPY ( select * from quote where date=: 'date' ) TO STDOU...
同样的错误:
\copy (select * from quote where date=:date) to '/tmp/result.csv'
如何修复它?
根据文档psql:
在你的情况下: