Re: plpgsql returning resultset

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Thomas Finneid <tfinneid(at)student(dot)matnat(dot)uio(dot)no>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: plpgsql returning resultset
Date: 2008-09-02 21:29:37
Message-ID: 48BDB041.40306@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 02/09/2008 22:19, Thomas Finneid wrote:
> for num_list in select num
> from table_part_num_list
> where se=se_arg
> loop
> table_name := 'table_part_'|| num_list.num;
>
> select * into val_list
> from table_name
> where st=st_arg and tr=tr_arg;
>
> return next val_list;

I think you need to build the query dynamically as a string, then
execute it using EXECUTE:

http://www.postgresql.org/docs/8.3/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

So something like this (I haven't tried it):

loop
execute 'select * into val_list from '
|| 'table_part_' || num_list.num
|| ' where st = st_arg and tr = tr_arg';
return next val_list;
end loop;

Hopefully this will work.

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-09-02 21:30:52 Re: How to create a case-insensitive unique constraint?
Previous Message Alex Vinogradovs 2008-09-02 21:28:35 Re: plpgsql returning resultset