Обсуждение: FOUND not set by EXECUTE?

Поиск
Список
Период
Сортировка

FOUND not set by EXECUTE?

От
David Wheeler
Дата:
I had expected the FOUND PL/pgSQL variable to be set by an UPDATE  
statement executed by an EXECUTE statement, but it doesn't appear to  
work:

try=# drop table try;
DROP TABLE
try=# CREATE TABLE try (
try(#   id integer
try(# );
CREATE TABLE
try=# INSERT INTO try VALUES (1);
INSERT 0 1
try=# CREATE OR REPLACE FUNCTION try_me () RETURNS VOID AS $$
try$# DECLARE
try$#   rcount integer;
try$# BEGIN
try$#    EXECUTE 'UPDATE try SET ID = 12';
try$#    RAISE NOTICE 'Found:     %', FOUND;
try$#    GET DIAGNOSTICS rcount = ROW_COUNT;
try$#    RAISE NOTICE 'Row Count: %', rcount;
try$# END;
try$# $$ LANGUAGE plpgsql SECURITY DEFINER;
CREATE FUNCTION
try=# SELECT try_me();
NOTICE:  Found:     f
NOTICE:  Row Count: 1
try_me
--------
(1 row)

Note that FOUND is false, but the ROW_COUNT fetched by GET  
DIAGNOSTICS is set to 1. So shouldn't FOUND be true? Or does it just  
not work with EXECUTE and need to be documented as such? Or am I just  
missing something obvious?

Thanks,

David


Re: FOUND not set by EXECUTE?

От
Tom Lane
Дата:
David Wheeler <david@kineticode.com> writes:
> Note that FOUND is false, but the ROW_COUNT fetched by GET  
> DIAGNOSTICS is set to 1. So shouldn't FOUND be true? Or does it just  
> not work with EXECUTE and need to be documented as such? Or am I just  
> missing something obvious?

It *is* documented: the manual lists the statements that affect FOUND,
and EXECUTE is not among them.

Whether it should be is another question, but that's a definition
disagreement (a/k/a enhancement proposal) not a bug.
        regards, tom lane


Re: FOUND not set by EXECUTE?

От
David Wheeler
Дата:
On Apr 8, 2006, at 14:38, Tom Lane wrote:

> It *is* documented: the manual lists the statements that affect FOUND,
> and EXECUTE is not among them.
>
> Whether it should be is another question, but that's a definition
> disagreement (a/k/a enhancement proposal) not a bug.

I think that:

a. It should be (it'd be very useful, without a doubt).
b. Until it is, the docs should explicitly mention that EXECUTE   does not affect found. No, EXECUTE is not in the
list,and   UPDATE, INSERT, and DELETE are, and although I'm using them   in an EXECUTE statement rather than directly
inthe PL/pgSQL,   it still seemed rather confusing, because they're still   UPDATE, INSERT, and DELETE.
 

So yes, it's a definition disagreement, but I think that things could  
be clearer.

Thanks,

David