pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christoph Haller <ch@rodos.fzk.de>
To: pgsql-sql@postgresql.org
Cc: Bryan_Klimt@baylor.edu
Subject: Re: insert rowtype
Date: Mon, 12 May 2003 10:42:21 +0200
Message-ID: <3EBF5E6D.5886CD73@rodos.fzk.de> (raw)

>
> 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




view thread (4+ messages)

Message-ID: <3EBF5E6D.5886CD73@rodos.fzk.de>
Permalink:  ../3EBF5E6D.5886CD73@rodos.fzk.de/
Also on:    postgresql.org/message-id/3EBF5E6D.5886CD73@rodos.fzk.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ch@rodos.fzk.de, Bryan_Klimt@baylor.edu
  Subject: Re: insert rowtype
  In-Reply-To: <3EBF5E6D.5886CD73@rodos.fzk.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox