Postgresql 不支持查询的时间戳值
Postgresql not supporting timestamp value on query
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
。
不要将值作为字符串文字传递。使用占位符并将它们作为 "native" 值传递。
此外,如果您想 select 来自 table 的源值,则不能使用 values
子句。插入语句是 either insert into tablename (column_one, column_two) values (value_one, value_two)
or 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 > '
using MAX_upd_date_Entity_Incident;
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
。
不要将值作为字符串文字传递。使用占位符并将它们作为 "native" 值传递。
此外,如果您想 select 来自 table 的源值,则不能使用 values
子句。插入语句是 either insert into tablename (column_one, column_two) values (value_one, value_two)
or 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 > '
using MAX_upd_date_Entity_Incident;