X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 488FE475956 for ; Mon, 12 May 2003 04:42:24 -0400 (EDT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by postgresql.org (Postfix) with SMTP id BB3F447580B for ; Mon, 12 May 2003 04:42:22 -0400 (EDT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Mon May 12 10:42:22 2003 +0200 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id KAA29760; Mon, 12 May 2003 10:42:22 +0200 (METDST) Message-ID: <3EBF5E6D.5886CD73@rodos.fzk.de> Date: Mon, 12 May 2003 10:42:21 +0200 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Cc: Bryan_Klimt@baylor.edu Subject: Re: insert rowtype Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-9.6 required=5.0 tests=BAYES_10,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1 autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/213 X-Sequence-Number: 13378 > > create or replace function updatetest(integer,varchar(32)) returns > integer as > ' > declare > -- the oid of the new row > newoid integer; > begin > -- duplicate the row > insert into test > select * from test t where > t.tmstamp=( > select max(tt.tmstamp) from test tt where tt.id=t.id > ) > and t.id=$1; > > -- get the oid of the new duplicate > get diagnostics newoid = result_oid; > > -- update the columns you want to change > update test set tmstamp=$2 where oid=newoid; > > -- return the new oid > return newoid; > end; > ' language plpgsql; > I only want to mention, this would insert multiple rows if the WHERE conditions do not specifiy a single row. Regards, Christoph