【发布时间】:2021-01-26 15:08:05
【问题描述】:
我在 Redshift 中创建并成功运行了存储过程,但没有按预期工作。 例如,我想删除参数设置的时间段内的数据。
-- 存储过程
CREATE OR REPLACE PROCEDURE sp_test(parm0 varchar(100), parm1 date, parm2 date)
AS '
BEGIN
EXECUTE
$_$ DELETE FROM test_table_b
WHERE $_$|| parm0 ||$_$
between $_$|| parm1 ||$_$ and $_$|| parm2 ||$_$ $_$;
end;
' language plpgsql;
-- 运行存储过程
Begin;
Call sp_test('opsdt', '2021-01-16', '2021-01-17');
Commit;
-- 结果
BEGIN executed successfully
Execution time: 0.07s
Statement 1 of 3 finished
0 rows affected
Call executed successfully
Execution time: 0.18s
Statement 2 of 3 finished
COMMIT executed successfully
Execution time: 0.13s
Statement 3 of 3 finished
Script execution finished
Total script execution time: 0.38s
脚本运行成功,但记录“2021-01-16”和“2021-01-17”仍保留在该表中。
任何建议将不胜感激。提前致谢。
【问题讨论】:
-
也许使用
RAISE NOTICE来输出DELETE 语句,以确认它包含您期望的变量? -
@John Rotenstein 非常感谢您的有用建议,约翰!似乎需要适当的报价。无论有没有 RAISE NOTICE,它现在都成功了。但是 RAISE NOTICE 可以帮助我了解实际执行的查询是警告并且非常有用。我真的很感谢你的好意。祝你有美好的一天:)
标签: amazon-web-services stored-procedures amazon-redshift