Re: temp tables in functions?

From: "Shoaib Mir" <shoaibmir(at)gmail(dot)com>
To: "Michael Fuhr" <mike(at)fuhr(dot)org>
Cc: "Bruno Wolff III" <bruno(at)wolff(dot)to>, jws <jsacksteder(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: temp tables in functions?
Date: 2007-02-08 10:38:31
Message-ID: bf54be870702080238k1e309cf9hc9c4b572f8ae5fe2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Agreed :) I guess missed out some details from there as I just thought he
needed to drop a temp table inside a function like this:

CREATE OR REPLACE function tempfunc (int) returns int
AS
$$
begin
execute 'create temporary table test (a numeric) on commit drop';
execute 'INSERT INTO test values (1);';
return 1;
end;
$$ LANGUAGE 'plpgsql'

.... used number by mistake so sorry for any inconvenience caused as I was
trying it with EnterpriseDB (where 'number 'is added for Oracle
compatibility)

--
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)

On 2/8/07, Michael Fuhr <mike(at)fuhr(dot)org> wrote:
>
> On Thu, Feb 08, 2007 at 12:29:37PM +0500, Shoaib Mir wrote:
> > Something like this will help you:
> >
> > execute immediate 'create temporary table test (a number) on commit
> drop';
>
> PL/pgSQL doesn't recognize "immediate" and number isn't a PostgreSQL
> type so the above yields a syntax error. Also, EXECUTE isn't
> necessary for the CREATE TABLE statement, although as Bruno mentioned
> EXECUTE will be necessary for other statements due to plan caching.
> And ON COMMIT DROP won't help if you call the function multiple
> times in the same transaction.
>
> --
> Michael Fuhr
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2007-02-08 10:41:25 Re: Persistent dead rows
Previous Message Michael Fuhr 2007-02-08 10:18:43 Re: temp tables in functions?