我想将具有特定user_id的日志数据移动到Redshift上的新表中。我已开始使用WITH
阻止like:
WITH moved_rows AS (
DELETE FROM sensor_log_enable
USING sensor_log_disable
WHERE sensor_log_enable.user_id
IN (16,17,18)
RETURNING sensor_log_enable.*
)
INSERT INTO sensor_log_disable
SELECT * FROM moved_rows;
但红移并不喜欢它。
ERROR: syntax error at or near "DELETE"
LINE 2: DELETE FROM active_connections
Redshift似乎不会在DELETE
块中包含WITH
。那么最好的策略是什么?
1 INSERT INTO
然后INNER JOIN
或LEFT OUTER JOIN
与DELETE
?
答案 0 :(得分:1)
要在表之间“移动”数据,您必须:
INSERT INTO
将数据复制到目标表DELETE
删除源表中的数据它们必须以单独的SQL命令执行。但是,您可以将这些命令包装在BEGIN / END语句中,以将它们作为一个事务提交:
BEGIN;
INSERT INTO...;
DELETE FROM...;
END;