From: | Christoph Haller <ch(at)rodos(dot)fzk(dot)de> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Cc: | Bryan_Klimt(at)baylor(dot)edu |
Subject: | Re: insert rowtype |
Date: | 2003-05-12 08:42:21 |
Message-ID: | 3EBF5E6D.5886CD73@rodos.fzk.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | J Sensel | 2003-05-12 10:39:52 | Looking for script to dump postgresql schema to xml file |
Previous Message | Peter Childs | 2003-05-12 04:47:48 | Re: Constraint Syntax Question |