Re: plpgsql: inserting a record into a (matching) table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Brian Hurt <bhurt(at)janestcapital(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: plpgsql: inserting a record into a (matching) table
Date: 2007-03-13 22:01:50
Message-ID: 10280.1173823310@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Brian Hurt <bhurt(at)janestcapital(dot)com> writes:
> I'd like to do is something like (note that this does not work):

> FOR t_rec IN
> SELECT * from foo_table WHERE primary_key = old_key
> t_rec.primary_key := new_key;
> t_rec.other_column := new_value;
> INSERT INTO foo_table VALUES ( t_rec ); -- Wrong- does not work

As of PG 8.2 I think that that will work if you say "t_rec.*" in the
VALUES. As-is, it's asking the system to insert a composite datum into
the first column of the table.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Eric 2007-03-16 16:28:49 Re: initdb fails - postgresql does not support leap seconds
Previous Message Tom Lane 2007-03-13 20:12:12 Re: Error 25P02 - transaction aborted - Potential causes?