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