Re: Elegant copy of a row using PL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
Cc: "richard lavoie" <richard_lavoie(at)gmx(dot)de>, pgsql-general(at)postgresql(dot)org
Subject: Re: Elegant copy of a row using PL
Date: 2007-01-16 18:07:21
Message-ID: 22199.1168970841@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Merlin Moncure" <mmoncure(at)gmail(dot)com> writes:
> On 1/16/07, richard lavoie <richard_lavoie(at)gmx(dot)de> wrote:
>> I've a table with 50 colums. I want to copy a certain row using PL and change only 2 values. The way to do it with insert is to long. Is there any other elegant way?

> the basic methodology is to:

> insert select into a scratch table;
> update scratch table;
> insert select back into real_table;

> scratch can be a persistent table (remember to truncate it) or a temp
> table. if it is a temp, remember to create it before you call your pl
> for the first time in a session.

Also, I think in 8.2 you could use a record variable in plpgsql.

declare r record;

select * into r from src where ...;
r.foo = whatever;
r.bar = whatever;
insert into dest values(r.*);

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lenorovitz, Joel 2007-01-16 18:10:25 Temp Table Within PLPGSQL Function - Something Awry
Previous Message Bruno Wolff III 2007-01-16 18:06:38 Re: Performance with very large tables