Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: Insert with...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 3455 of 3799
Post > Topic >>

Re: Insert with pl/pgsql trigger

by tgl@[EMAIL PROTECTED] (Tom Lane) May 7, 2008 at 11:24 AM

"Woody Woodring" <george.woodring@[EMAIL PROTECTED]
> writes:
> My trigger is :
> CREATE OR REPLACE FUNCTION log_cpe_health() RETURNS trigger AS '
>    DECLARE
>    BEGIN
>       -- Update last outage before inserting
>       EXECUTE ''INSERT INTO cpe_health_history VALUES '' || NEW;
>    END;
> ' LANGUAGE plpgsql;

That's never going to work because of quoting issues, and it wouldn't be
an efficient way if it did work (because of having to re-parse and
re-plan the INSERT each time).  And if it did act the way you are
imagining, it still wouldn't be a good way because you typically want
some additional columns in the log table, such as a timestamp.

In recent releases you can do it like this:

	INSERT INTO cpe_health_history VALUES (NEW.*);

which can be extended to, eg,

	INSERT INTO cpe_health_history VALUES (NEW.*, now());

			regards, tom lane

-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 2 Posts in Topic:
Insert with pl/pgsql trigger
george.woodring@[EMAIL PR  2008-05-07 10:36:26 
Re: Insert with pl/pgsql trigger
tgl@[EMAIL PROTECTED] (T  2008-05-07 11:24:21 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 21:47:26 CST 2008.