我意识到我无法为 SELECT 创建触发器,因此依赖于 RULES。
CREATE OR REPLACE RULE log_select AS
ON SELECT TO usertable
DO ALSO INSERT INTO selectLOG(prim_key,val)
VALUES(prim_key,val);
上面的示例不适用于以下错误:
ERROR: column "prim_key" does not exist
LINE 4: VALUES(prim_key,val)
^
HINT: There is a column named "prim_key" in table "old", but
it cannot be referenced from this part of the query.
基本上,当用户在 table1 上进行 SELECT 时,我想将行插入 table2。