Re: insert rowtype - Mailing list pgsql-sql

From Christoph Haller
Subject Re: insert rowtype
Date
Msg-id 3EBF5E6D.5886CD73@rodos.fzk.de
Whole thread Raw
In response to insert rowtype  (Bryan Klimt <Bryan_Klimt@baylor.edu>)
List pgsql-sql
>
> 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



pgsql-sql by date:

Previous
From: Peter Childs
Date:
Subject: Re: Constraint Syntax Question
Next
From: Lucas Lain
Date:
Subject: Re: epoch to timestamp