Re: Inserting a record data type into a table - Mailing list pgsql-general

From Tom Lane
Subject Re: Inserting a record data type into a table
Date
Msg-id 29725.1113230737@sss.pgh.pa.us
Whole thread Raw
In response to Inserting a record data type into a table  (Graeme Hinchliffe <graeme.hinchliffe@zeninternet.co.uk>)
List pgsql-general
Graeme Hinchliffe <graeme.hinchliffe@zeninternet.co.uk> writes:
> what I would like to be able to do is simply
> INSERT INTO newtable VALUES (NEW);

In 8.0 it works to spell it "new.*".

regression=# create table z1 (f1 int, f2 text);
CREATE TABLE
regression=# create table z2 (f1 int, f2 text);
CREATE TABLE
regression=# create function z1t() returns trigger as $$
regression$# begin
regression$#   insert into z2 values(new.*);
regression$#   return new;
regression$# end$$ language plpgsql;
CREATE FUNCTION
regression=# create trigger z1t  before insert on z1 for each row
regression-# execute procedure z1t();
CREATE TRIGGER
regression=# insert into z1 values (42, 'foo');
INSERT 0 1
regression=# select * from z2;
 f1 | f2
----+-----
 42 | foo
(1 row)

regression=#

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Time and date functions give me headaches!!
Next
From: David Fetter
Date:
Subject: Re: What are the consequences of a bad database design