From: | Torsten Zühlsdorff <foo(at)meisterderspiele(dot)de> |
---|---|
To: | Dmitriy Igrishin <dmitigr(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: [TRIGGER] Returning values from BEFORE UPDATE trigger, without using them |
Date: | 2010-07-26 07:41:23 |
Message-ID: | 4C4D3C23.2090804@meisterderspiele.de |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hey Dmitriy,
thanks for your reply.
> I think, its would be better to use rule on update instead of the trigger
> in such case as you.
I've played the whole weekend with the rule-system, but it didn't work
for my case. I have a dynamic trigger, which takes cares about revision
of rows for every table, it is called from. It looks like that:
CREATE OR REPLACE FUNCTION versionizeContent()
RETURNS TRIGGER
AS $$
BEGIN
/* add new version in central register and insert new row */
NEW.revision := addContentRevision (OLD.content_id, OLD.revision,
sessval('user_id')::int));
EXECUTE 'INSERT INTO ' || quote_ident(TG_TABLE_NAME) ||
' SELECT (' || QUOTE_LITERAL(NEW) || '::' ||
quote_ident(TG_TABLE_NAME) ||').*' ;
RETURN NULL;
END;
$$ LANGUAGE 'plpgsql' VOLATILE;
Even if i drop the dynamic INSERT-Part and write it for every relation,
i wasn't able to figured out how to manipulate the NEW-Record.
The best i tried so far was:
CREATE RULE "versionize"
AS ON UPDATE
TO templates
DO INSTEAD
(
SELECT addContentRevision (OLD.content_id, OLD.revision,
sessval('user_id')::int) INTO NEW.revision;
INSERT INTO templates SELECT NEW.* RETURNING *;
);
But an Updates ends with the ERROR:
"ERROR: schema "*NEW*" does not exist"
Has anyone a hint how to manipulate the NEW record within an RULE?
Thanks,
Torsten
From | Date | Subject | |
---|---|---|---|
Next Message | Enrique Palacios | 2010-07-26 13:55:52 | Returning only alphanumeric values from a query |
Previous Message | Joshua Tolley | 2010-07-24 11:47:24 | Re: howto delete using a join ? |