Re: Alternative to temp tables?

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Postgres User <postgres(dot)developer(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Alternative to temp tables?
Date: 2009-09-12 06:58:30
Message-ID: dcc563d10909112358v57fa95fdh57fa0cd0083e599b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Sep 12, 2009 at 12:51 AM, Postgres User
<postgres(dot)developer(at)gmail(dot)com> wrote:
> Hi,
>
> I have a simple function that returns a set of rows:
>
> CREATE OR REPLACE FUNCTION foo()
>  RETURNS SETOF record AS
> $$
> BEGIN
>    RETURN QUERY SELECT * FROM people WHERE last_name = 'jones';
> END
> $$
> LANGUAGE 'plpgsql'
>
> In a separate function, I call the function and store the results in a
> temp table using this syntax:
>
> INSERT INTO tmp_tbl SELECT * FROM foo()
>
>
> This works, but I'd like to know if there's another way to hold the
> results.  Can I get the results from foo() and store those in a local
> var such as
>
> recs record[]   OR
> recs people[]
>
> Or are temp tables the only way to hold table-based results?

Nope, starting with pg 8.4 you can create temp result sets with the
WITH keyword.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2009-09-12 09:58:31 Re: Loop
Previous Message Postgres User 2009-09-12 06:51:40 Alternative to temp tables?