Re: Bug #710: Fail To Create/Drop Temporary Table IN PL/PGSQL

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: <cnliou(at)eurosport(dot)com>, <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Bug #710: Fail To Create/Drop Temporary Table IN PL/PGSQL
Date: 2002-07-12 03:16:31
Message-ID: 20020711195907.V953-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


On Thu, 11 Jul 2002 pgsql-bugs(at)postgresql(dot)org wrote:

> CNLIOU (cnliou(at)eurosport(dot)com) reports a bug with a severity of 2
> The lower the number the more severe it is.
>
> Short Description
> Fail To Create/Drop Temporary Table IN PL/PGSQL
>
> Long Description
> Hi!
>
> In TODO list, it reads in sub section
>
> "Fix problems with complex temporary table creation/destruction
> without using PL/PgSQL EXECUTE, needs cache prevention/invalidation"
>
> in section "SERVER-SIDE LANGUAGES".
>
> According to this statement, I am in the impression that I can
> create/destruct temporary table with "execute" statement, but actually
> I can't.
>
> Perhaps this can be added to TODO list, too.
>
> Also, being unable to use temporary table in PL/PGSQL, I can not
> proceed working on part of my project.

You need to use EXECUTE on all statements dealing with the table
you are creating and dropping, but there is an issue that I don't
know of a direct way to select into a field with EXECUTE apart from
what I do below.

CREATE OR REPLACE FUNCTION test() RETURNS BOOLEAN AS '
DECLARE
n INTEGER;
r RECORD;
BEGIN
EXECUTE ''CREATE TEMP TABLE temp1 (MyField INTEGER)'';
EXECUTE ''INSERT INTO temp1 VALUES(8);'';

FOR r IN EXECUTE ''SELECT MyField FROM temp1 LIMIT 1'' LOOP
n := r.MyField;
END LOOP;
RAISE NOTICE ''%'',n;

EXECUTE ''DROP TABLE temp1'';
RETURN TRUE;
END;' LANGUAGE 'plpgsql';

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2002-07-12 03:36:06 Re: 7.2.1 backend crash (convert_string_datum, locale)
Previous Message Tom Lane 2002-07-12 03:15:42 Re: 7.2.1 backend crash (convert_string_datum, locale)