Re: [GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Josh Trutwin
On Thu, 6 Aug 2009 16:58:02 -0400 Michael Glaesemann wrote: > That's not a SELECT query per se: AIUI it's how the evaluation of > the NEW != OLD expression is evaluated within the PL/pgSQL function > as part of the IF statement (note the "line 2 at IF" context line). > It's just saying the <> ope

Re: [GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Merlin Moncure
On Thu, Aug 6, 2009 at 3:31 PM, Josh Trutwin wrote: > On Thu, 6 Aug 2009 13:15:57 -0400 > Merlin Moncure wrote: > >> CREATE OR REPLACE FUNCTION set_last_modified () >> RETURNS TRIGGER >> AS $$ >> BEGIN >>   IF NEW != OLD THEN  -- 8.4 syntax >>     NEW.last_modified = NOW(); >>   END IF; >> >>   RE

Re: [GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Michael Glaesemann
On Aug 6, 2009, at 15:31 , Josh Trutwin wrote: Interestingly, this syntax is accepted in 8.3.7, but SELECT queries fail: CREATE TRIGGER trigger_test_upd_set_last_mod BEFORE UPDATE ON test_upd FOR EACH ROW EXECUTE PROCEDURE set_last_modified(); Then: UPDATE test_upd SET foo = 'foo' WHERE id =

Re: [GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Josh Trutwin
On Thu, 6 Aug 2009 13:15:57 -0400 Merlin Moncure wrote: > CREATE OR REPLACE FUNCTION set_last_modified () > RETURNS TRIGGER > AS $$ > BEGIN > IF NEW != OLD THEN -- 8.4 syntax > NEW.last_modified = NOW(); > END IF; > > RETURN NEW; > END; > $$ LANGUAGE PLPGSQL; Interestingly, this synt

Re: [GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Josh Trutwin
On Thu, 6 Aug 2009 13:15:57 -0400 Merlin Moncure wrote: > CREATE OR REPLACE FUNCTION set_last_modified () > RETURNS TRIGGER > AS $$ > BEGIN > IF NEW != OLD THEN -- 8.4 syntax > NEW.last_modified = NOW(); > END IF; > > RETURN NEW; > END; > $$ LANGUAGE PLPGSQL; Thanks - I'll try this.

Re: [GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Merlin Moncure
On Thu, Aug 6, 2009 at 1:38 PM, Jeff Davis wrote: > On Thu, 2009-08-06 at 13:15 -0400, Merlin Moncure wrote: >> in 8.4 you can (and should) do: >> WHERE old = new > > I couldn't get that to work in a rule. it should, maybe try old::foo = new::foo >>   IF NEW != OLD THEN  -- 8.4 syntax > > Does th

Re: [GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Pavel Stehule
2009/8/6 Jeff Davis : > On Thu, 2009-08-06 at 13:15 -0400, Merlin Moncure wrote: >> in 8.4 you can (and should) do: >> WHERE old = new > > I couldn't get that to work in a rule. > >>   IF NEW != OLD THEN  -- 8.4 syntax > > Does this work correctly in the case of NULLs? It looks like it does, > but

Re: [GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Jeff Davis
On Thu, 2009-08-06 at 13:15 -0400, Merlin Moncure wrote: > in 8.4 you can (and should) do: > WHERE old = new I couldn't get that to work in a rule. > IF NEW != OLD THEN -- 8.4 syntax Does this work correctly in the case of NULLs? It looks like it does, but that seems strange, because ROW(1, N

Re: [GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Jeff Davis
On Thu, 2009-08-06 at 11:53 -0500, Josh Trutwin wrote: > The set_last_modified() trigger is run even though the data didn't > actually change. Perhaps due to an application program which doesn't > know the contents before running the UPDATE. The following doc explains the standard way to accompli

Re: [GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Merlin Moncure
On Thu, Aug 6, 2009 at 12:53 PM, Josh Trutwin wrote: > Hello, > > I have a simple table that has a trigger to set a last_modified column > using the following: > > CREATE OR REPLACE FUNCTION set_last_modified () > RETURNS TRIGGER > AS $$ >   BEGIN >      NEW.last_modified = NOW(); >      RETURN NEW

[GENERAL] Empty Updates, ON UPDATE triggers and Rules

2009-08-06 Thread Josh Trutwin
Hello, I have a simple table that has a trigger to set a last_modified column using the following: CREATE OR REPLACE FUNCTION set_last_modified () RETURNS TRIGGER AS $$ BEGIN NEW.last_modified = NOW(); RETURN NEW; END; $$ LANGUAGE PLPGSQL; CREATE TRIGGER trigger_test_upd_set_la