postgresql - 带有查询的 Unix shell 脚本不会为带有 where 子句的查询生成数据,但如果没有 where 子句,它正在为 postgres 元数据生成数据
问题描述
我在 shell 脚本中使用 Postgres 查询来执行并获得一些结果并加载到文件中。该查询使用 where 子句,其中日期列用于 postgres 数据库。如果没有 where 子句,它正在生成数据,但在查询中使用 where 子句,它不会生成数据。以下是示例查询以供参考。
psql -h host -p port -U username -w -d databasename -Atc
"with A as( select max(col1) as max_inst_id,col2,col3,col4 from
sch_task_Inst where col5 > timestamp '2018-05-05 02:00:00 - interval
'1 hours' group by col1,col2,col3,col4 )
select b.col1 as task_nm,A.col1 as run_status,A.col2 as run_log from
A join sch_task b on A.col1 = b.col1 where A.col2 = 'FAI' ;" >>
/app/ditechstyle/diserver/app/source/Sch_test.dat
有人可以告诉我查询 where 子句有什么问题吗?
解决方案
您的问题是您在时间戳之后缺少一个撇号。你应该有timestamp '2018-05-05 02:00:00' - interval '1 hours'
,但你实际拥有的是timestamp '2018-05-05 02:00:00 - interval '1 hours'
。注意后面的撇号02:00:00
。请参阅此页面上有关 PostgreSQL 日期和时间戳的示例。
推荐阅读
- wpf - Prism/WPF 中的新外壳/窗口显示错误视图
- awk - 双向运算符如何用于 (g)awk?
- kubernetes - 自动设置具有多个 pod 的 Kubernetes 集群
- vba - 如何显示带有法语口音的字母:é 和其他喜欢的字母?
- c - 为什么当经过的时间很短时,clock() 函数有时不准确?
- .net - [AfterStep] 中的断言未设置 ScenarioContext.Current.TestError
- postgresql - 多次更新性能提升
- php - 如果对象 id 已知,Laravel 获取对象属性
- android - 我无法在活动中导入 java.util.date
- tensorflow - model.compile 的两种描述得到不同的结果