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 > Insert with pl/...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 3455 of 3558
Post > Topic >>

Insert with pl/pgsql trigger

by george.woodring@[EMAIL PROTECTED] ("Woody Woodring") May 7, 2008 at 10:36 AM

I am trying to create a table that is a log of another table in 8.3.1 using
a trigger.  Both tables look like

   Table "public.cpe_health_history"
     Column    |    Type    | Modifiers
 --------------+------------+-----------
 cpe_healthid | integer    | not null
 mac          | macaddr    |
 polldate     | integer    |
 health       | smallint   |
 rank         | smallint   |
 data         | integer[]  |
 alarm        | smallint[] |


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;

-- Create Trigger on outagelog table
CREATE TRIGGER cpe_health_log AFTER INSERT OR UPDATE ON dhct_health
   FOR EACH ROW EXECUTE PROCEDURE log_cpe_health();


I am getting the following error:

health-test=> INSERT INTO dhct_health (mac, polldate, health, rank, data,
alarm) VALUES ('000000000001', 1210169492, 3, 9, '{2, 4,6}', '{3,3,3}');
ERROR:  syntax error at or near ":"
LINE 1: INSERT INTO cpe_health_history VALUES (7,00:00:00:00:00:01,1...
                                                   ^
QUERY:  INSERT INTO cpe_health_history VALUES
(7,00:00:00:00:00:01,1210169492,3,9,"{2,4,6}","{3,3,3}")
CONTEXT:  PL/pgSQL function "log_cpe_health" line 4 at EXECUTE statement

If I change the insert on the command line to (it works):

health-test=> INSERT INTO cpe_health_history VALUES
(7,'00:00:00:00:00:01',1210169492,3,9,'{2,4,6}','{3,3,3}');
INSERT 0 1

Am I using the "NEW" parameter wrong?

Thanks,
Woody

----------------------------------------
iGLASS Networks
3300 Green Level Rd. West
Cary NC 27519
(919) 387-3550 x813
www.iglass.net


-- 
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
tan13V112 Fri Jul 4 22:59:35 CDT 2008.