Re: Inserting a record data type into a table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Graeme Hinchliffe <graeme(dot)hinchliffe(at)zeninternet(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Inserting a record data type into a table
Date: 2005-04-11 14:45:37
Message-ID: 29725.1113230737@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Graeme Hinchliffe <graeme(dot)hinchliffe(at)zeninternet(dot)co(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2005-04-11 14:58:54 Re: What are the consequences of a bad database design
Previous Message Tom Lane 2005-04-11 14:33:23 Re: Time and date functions give me headaches!!