Unix Technical Forum

Elegant copy of a row using PL

This is a discussion on Elegant copy of a row using PL within the Pgsql General forums, part of the PostgreSQL category; --> Hi! I'm not sure about the English terminology for that so I'm sorry if I made a mistake on ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 01:24 PM
richard lavoie
 
Posts: n/a
Default Elegant copy of a row using PL

Hi!


I'm not sure about the English terminology for that so I'm sorry if I made a
mistake on the subject and on this message.

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?

Thank you very much
Richard
--
"Feel free" - 5 GB Mailbox, 50 FreeSMS/Monat ...
Jetzt GMX ProMail testen: http://www.gmx.net/de/go/promail

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 01:24 PM
Merlin Moncure
 
Posts: n/a
Default Re: Elegant copy of a row using PL

On 1/16/07, richard lavoie <richard_lavoie@gmx.de> wrote:
> Hi!
>
>
> I'm not sure about the English terminology for that so I'm sorry if I made a
> mistake on the subject and on this message.
>
> 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.

merlin

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 01:24 PM
Tom Lane
 
Posts: n/a
Default Re: Elegant copy of a row using PL

"Merlin Moncure" <mmoncure@gmail.com> writes:
> On 1/16/07, richard lavoie <richard_lavoie@gmx.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

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org/

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:41 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com