Обсуждение: Trigger.. AFTER and BEFORE with specific column changed
*I'm trying to follow this :*
CREATE TRIGGER check_update
*BEFORE* UPDATE ON accounts
FOR EACH ROW
WHEN (OLD.balance IS DISTINCT FROM NEW.balance)
EXECUTE PROCEDURE check_account_update();
*but with AFTER instead of BEFORE. and I'm keep getting error on or near
WHEN.
does that because i have to use BEFORE ? what if i need to execute the
procedure after updating column and it has really changed.*
--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Trigger-AFTER-and-BEFORE-with-specific-column-changed-tp5610712p5610712.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
On 04/01/2012 11:45 AM, Albert wrote: > *I'm trying to follow this :* > > > CREATE TRIGGER check_update > *BEFORE* UPDATE ON accounts > FOR EACH ROW > WHEN (OLD.balance IS DISTINCT FROM NEW.balance) > EXECUTE PROCEDURE check_account_update(); > > *but with AFTER instead of BEFORE. and I'm keep getting error on or near > WHEN. What is the error message? > does that because i have to use BEFORE ? what if i need to execute the > procedure after updating column and it has really changed.* Depends what the procedure is doing. For more detail on what the WHEN does in BEFORE and AFTER triggers see here: http://www.postgresql.org/docs/9.0/interactive/sql-createtrigger.html Look for the Notes section. > > -- > View this message in context: http://postgresql.1045698.n5.nabble.com/Trigger-AFTER-and-BEFORE-with-specific-column-changed-tp5610712p5610712.html > Sent from the PostgreSQL - general mailing list archive at Nabble.com. > -- Adrian Klaver adrian.klaver@gmail.com
*i get:* Syntax error at or near 'WHEN' LINE 1: ... check_update AFTER UPDATE ON accounts FOR EACH ROW WHEN (OLD.balance IS DISTINCT FROM NEW.balance) .... -- View this message in context: http://postgresql.1045698.n5.nabble.com/Trigger-AFTER-and-BEFORE-with-specific-column-changed-tp5610712p5611501.html Sent from the PostgreSQL - general mailing list archive at Nabble.com.
On 04/01/2012 10:10 PM, Albert wrote: > *i get:* > > Syntax error at or near 'WHEN' > LINE 1: ... check_update AFTER UPDATE ON accounts FOR EACH ROW WHEN > (OLD.balance IS DISTINCT FROM NEW.balance) .... Hmmm. So two questions: What happens if you copy the example in the docs exactly and use NEW.* and OLD.*? What is the table definition for accounts? > > -- > View this message in context: http://postgresql.1045698.n5.nabble.com/Trigger-AFTER-and-BEFORE-with-specific-column-changed-tp5610712p5611501.html > Sent from the PostgreSQL - general mailing list archive at Nabble.com. > -- Adrian Klaver adrian.klaver@gmail.com
Albert <oo_O2_oo@hotmail.com> writes:
> *i get:*
> Syntax error at or near 'WHEN'
> LINE 1: ... check_update AFTER UPDATE ON accounts FOR EACH ROW WHEN
> (OLD.balance IS DISTINCT FROM NEW.balance) ....
Does the BEFORE case work for you either? I'm suspicious that you
are using a PG version that predates WHEN-clause support in triggers.
regards, tom lane
Aleksander Rozman wrote:
> Now I am not sure two of this directories are old databases, but I think
> they are... Is there a way to register one of this databases into new
> installation (I am sure that directory "1" is old postgres database, and
> "11563" is my database I want to save, and "11564" is new postgresql
> database (this is only directory with new date).
Actually 1, 11563 and 11564 are what you get with a fresh new installation.
On a 8.4 install on Ubuntu, the corresponding databases are:
SELECT oid, datname from pg_database where oid in (1,11563,11564);
oid | datname
-------+-----------
1 | template1
11563 | template0
11564 | postgres
Also normally initdb wouldn't work on a non-empty data directory, anyway.
I'd say that either the old data directory has been moved aside at some point
of the upgrade procedure, or it has been wiped out :(
Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org