RULE - special variables?
Do rules get special variables like triggers? Can I set variables in them like
triggers?
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail.
http://new.mail.yahoo.com
Matthew Peter wrote:
Do rules get special variables like triggers? Can I set variables in them like
triggers?
You get NEW/OLD but they mean something subtly different. Rules act on a
query-tree so they are more like placeholders.
You can't set variables in triggers. You do so in a function. If your
rule calls a function, that could have variables.
Spend some time playing with rules - make sure you understand the
difference between them and triggers.
--
Richard Huxton
Archonet Ltd
Do rules get special variables like triggers? Can I set
variables in them like
triggers?
A rule is one or more SQL-Statements - how do you set variables in SQL?
Don't think of a rule as a program!
In a statement in a rule, you have the pseudotables 'OLD' and 'NEW'
which refer to the affected rows of the table on which the rule is
defined, OLD (in DELETE and UPDATE rules) referring to the values before
the triggering statement takes place, and NEW (in INSERT and UPDATE)
referring to the values afterwards.
Yours,
Laurenz Albe
Import Notes
Resolved by subject fallback
Albe Laurenz wrote:
Do rules get special variables like triggers? Can I set
variables in them like
triggers?A rule is one or more SQL-Statements - how do you set variables in SQL?
SET [ SESSION | LOCAL ] name { TO | = } { value | 'value' | DEFAULT }
http://www.postgresql.org/docs/8.1/interactive/sql-set.html
--
Shane Ambler
pgSQL@007Marketing.com
Get Sheeky @ http://Sheeky.Biz
Shane Ambler wrote:
Albe Laurenz wrote:
Do rules get special variables like triggers? Can I set variables in
them like
triggers?A rule is one or more SQL-Statements - how do you set variables in SQL?
SET [ SESSION | LOCAL ] name { TO | = } { value | 'value' | DEFAULT }
That's configuration settings, not user-defined variables though.
--
Richard Huxton
Archonet Ltd
--- Richard Huxton <dev@archonet.com> wrote:
Matthew Peter wrote:
Do rules get special variables like triggers? Can I set variables in them like
triggers?You get NEW/OLD but they mean something subtly different. Rules act on a
query-tree so they are more like placeholders.You can't set variables in triggers. You do so in a function. If your
rule calls a function, that could have variables.
You can set variables in triggers in the DECLARE block when plpgsql is used.
Reading the docs they only show single-statement rules so it never said assigning
could be done so here I am. Sometimes it's easier to write a quick rule than a
trigger function and separate firing condition, especially when they function so
similiarily in theory. Thanks.
____________________________________________________________________________________
Cheap talk?
Check out Yahoo! Messenger's low PC-to-Phone call rates.
http://voice.yahoo.com