Re: Error working with Temporary Sequences in plpgsql in 8.1 (8.0 works fine)
От
Jaime Casanova
Тема
Re: Error working with Temporary Sequences in plpgsql in 8.1 (8.0 works fine)
Дата
Msg-id
c2d9e70e0601171028o1848602epbf7d550754e106ee@mail.gmail.com
Ответ на
Error working with Temporary Sequences in plpgsql in 8.1 (8.0 works
fine) (Daniel Schuchardt)
Список
Дерево обсуждения
Error working with Temporary Sequences in plpgsql in 8.1 (8.0 works
fine) Daniel Schuchardt <daniel_schuchardt@web.de>
Re: Error working with Temporary Sequences in plpgsql in 8.1 (8.0 works fine) Jaime Casanova <systemguards@gmail.com>
Re: Error working with Temporary Sequences in plpgsql in 8.1 (8.0 works fine) Michael Fuhr <mike@fuhr.org>
Re: Error working with Temporary Sequences in plpgsql in 8.1 (8.0 Daniel Schuchardt <daniel_schuchardt@web.de>
On 1/17/06, Daniel Schuchardt wrote:
> Hi,
>
> here is a testcase:
>
> CREATE OR REPLACE FUNCTION testseq()
> RETURNS void AS
> $BODY$
> BEGIN
> CREATE TEMP SEQUENCE test;
> PERFORM testseq1();
> DROP SEQUENCE test;
> RETURN;
> END; $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
> ALTER FUNCTION testseq() OWNER TO postgres;
>
>
> CREATE OR REPLACE FUNCTION testseq1()
> RETURNS void AS
> $BODY$
> DECLARE I INTEGER;
> BEGIN
> I:= nextval('test');
> RETURN;
> END; $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
> ALTER FUNCTION testseq1() OWNER TO postgres;
>
>
> SELECT testseq();
>
> -- this works fine.
>
> SELECT testseq();
>
>
> ERROR: could not open relation with OID 21152
> CONTEXT: PL/pgSQL function "testseq1" line 3 at assignment
> SQL statement "SELECT testseq1()"
> PL/pgSQL function "testseq" line 3 at perform
>
>
>
> Greetings,
>
> Daniel.
>
try this way:
CREATE OR REPLACE FUNCTION testseq() RETURNS void AS
$BODY$BEGIN EXECUTE 'CREATE TEMP SEQUENCE test'; PERFORM testseq1(); DROP SEQUENCE test; RETURN;END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION testseq() OWNER TO postgres;
CREATE OR REPLACE FUNCTION testseq1() RETURNS void AS
$BODY$DECLARE I INTEGER;BEGIN EXECUTE 'select nextval(''test'')' INTO I;
raise notice '%', I; RETURN;END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION testseq1() OWNER TO postgres;
SELECT testseq();
SELECT testseq();
is the same problem as with temp tables, you must put their creation,
and in this case even the nextval in an execute...
--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)
В списке pgsql-hackers по дате отправления