Re: problem with FOUND and EXECUTE in pl/pgsql

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org
Subject: Re: problem with FOUND and EXECUTE in pl/pgsql
Date: 2009-06-04 05:32:09
Message-ID: 162867790906032232k32623653n922c205219dcbb8c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2009/6/4 Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>:
> On Wed, 3 Jun 2009, Tom Lane wrote:
>
>> Oleg Bartunov <oleg(at)sai(dot)msu(dot)su> writes:
>>>
>>> seems I don't understand how FOUND variable in pl/pgsql function defined,
>>> when I use EXECUTE of PERFORM. There is no problem when I use plain SQL.
>>
>> EXECUTE doesn't affect FOUND, even if the statement-to-be-executed would
>> have.  There's been some discussion about changing that, but no
>> movement.
>
> I think this should be clarified in docs. Hmm, simple update-or-insert
> function in case of EXECUTE became
> complicated. I had to use RETURNING xxx INTO yyy and check yyy for NULL
> value.

use GET DIAGNOSTICS

postgres=# create table ff(a integer);
CREATE TABLE
Time: 130,222 ms
postgres=#
create or replace function t(int) returns void as $$
declare r integer;
begin
execute 'insert into f values($1)' using $1;
get diagnostics r = ROW_COUNT;
raise notice '%', r;
return;
end;
$$ language plpgsql;
CREATE FUNCTION
Time: 129,132 ms
postgres=# select t(29);

NOTICE: 1
t
---

(1 row)

Time: 51,979 ms
postgres=#

Regards
Pavel Stehule

>
>        Regards,
>                Oleg
> _____________________________________________________________
> Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru),
> Sternberg Astronomical Institute, Moscow University, Russia
> Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
> phone: +007(495)939-16-83, +007(495)939-23-83
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message youngvonlee@gmail.com 2009-06-04 05:52:58 postgresql source code is worth to read
Previous Message Bruce Momjian 2009-06-04 04:01:08 Re: Accessing pg_controldata information from SQL