0
這是BEFORE
觸發器插入到右table partition之一:BEFORE觸發+ RETURNING返回NULL
CREATE OR REPLACE FUNCTION public.insert_install_session()
RETURNS trigger
LANGUAGE plpgsql
AS
$body$
BEGIN
IF (NEW.created >= '2015-10-01 00:00:00' AND NEW.created < '2015-10-02 00:00:00') THEN
INSERT INTO install_session_2015_10_01 VALUES (NEW.*);
ELSIF (NEW.created >= '2015-10-02 00:00:00' AND NEW.created < '2015-10-03 00:00:00') THEN
INSERT INTO install_session_2015_10_02 VALUES (NEW.*);
ELSIF (NEW.created >= '2015-09-30 00:00:00' AND NEW.created < '2015-10-01 00:00:00') THEN
INSERT INTO install_session_2015_09_30 VALUES (NEW.*);
ELSE
RETURN NEW;
END IF;
RETURN NULL;
END;
$body$
CREATE TRIGGER trigger_insert_install_session
BEFORE INSERT ON install_session
FOR EACH ROW EXECUTE PROCEDURE insert_install_session
和我有一個使用RETURNING
查詢:
INSERT INTO "install_session"
(<columns here>)
VALUES
(<values here>)
RETURNING "install_session"."id";
我怎樣才能讓RETURNING
工作?它似乎總是返回NULL。
是否因爲函數結尾的RETURN NULL
?我不能返回NEW
,因爲該行將被插入第二次,不是嗎?這裏是official docs。
規則會與PARTITIONS一起使用嗎?不幸的是我不能修改使用RETURNING的代碼,所以currval()不適合我。感謝您指出它。 – kev