postgresql - Postgresql 不支持查询的时间戳值
问题描述
DECLARE
MAX_upd_date_Entity_Incident timestamp without time zone;
MAX_upd_date_Entity_Incident := (SELECT LAST_UPDATE_DATE::timestamp FROM
test.table_1 where TABLE_NAME='mac_incidents_d');
execute 'insert into test.table2 (column_name,schema_name,tablename)
values(''col1'',''col2'',''col3'') from test.table3 X where X.dl_upd_ts::timestamp > '||
MAX_upd_date_Entity_Incident;
上面的查询没有被执行,时间戳值出错,无法读取变量MAX_upd_date_Entity_Incident
。
如果我们需要将时间戳转换为另一种格式,请建议我。
我可以在 SQL 编辑器中执行查询,但不能使用execute
.
解决方案
不要将值作为字符串文字传递。使用占位符并将它们作为“本机”值传递。
values
此外,如果要从表中选择源值,则不能使用该子句。插入语句要么是要么 insert into tablename (column_one, column_two) values (value_one, value_two)
insert into (column_one, column_two) select c1, c2 from some_table
我也认为不需要动态 SQL:
insert into test.table2 (column_name,schema_name,tablename)
select col1,col2,col3
from test.table3 X
where X.dl_upd_ts::timestamp > MAX_upd_date_Entity_Incident;
如果你过度简化了你的例子并且你确实需要动态 SQL,你应该使用这样的东西:
execute 'insert into test.table2 (column_name,schema_name,tablename)
select col1,col2,col3) from test.table3 X where X.dl_upd_ts::timestamp > $1'
using MAX_upd_date_Entity_Incident;
推荐阅读
- node.js - 批量检查 Firestore 文档的最佳方法是什么,如果未创建则添加文档?
- conditional-statements - 如何在 Blogger 的一个条件标签中使用 2 个标签
- javascript - 根据用户是否登录更改网站上的文本
- javascript - 如何在 selenium 中访问返回的 JavaScript 承诺值?
- c# - UseStatusCodePagesWithReExecute 显示空白页
- c - 将输入字符串转换为十六进制不会产生正确的大小
- r - 根据 1 个列表将列表列表转换为数据框 - 每个列表都不同
- firebase - 获取 firebase/firestore SERVERTIME 并转换为日期(月和日)
- ios - 我得到一个不能为 nil obj c 的参数的错误
- c - execve 系统调用中的 envp 不包含字符串“LS_C”的任何 execpt