Re: plpgsql returning resultset - Mailing list pgsql-general

From Raymond O'Donnell
Subject Re: plpgsql returning resultset
Date
Msg-id 48BDB041.40306@iol.ie
Whole thread Raw
In response to Re: plpgsql returning resultset  (Thomas Finneid <tfinneid@student.matnat.uio.no>)
List 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@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

pgsql-general by date:

Previous
From: "Roberts, Jon"
Date:
Subject: Re: Foreign Key normalization question
Next
From: Tom Lane
Date:
Subject: Re: How to create a case-insensitive unique constraint?