Re: plpgsql question - Mailing list pgsql-general

From Adrian Klaver
Subject Re: plpgsql question
Date
Msg-id 201112050711.45364.adrian.klaver@gmail.com
Whole thread Raw
In response to plpgsql question  ("Gauthier, Dave" <dave.gauthier@intel.com>)
List pgsql-general
On Monday, December 05, 2011 6:59:32 am Gauthier, Dave wrote:
> v8.3.4 on linux
>
> Is there a way to set the query used in a "for rec in (query) loop -> end
> loop" be a variable?  Example
>
> if (foo = 'whatever')
> then
>   sqlstmt := "select x,y,z ...";
> else
>   sqlstmt := "select a,b,c ...";
> end if ;
>
> for therec in
>   sqlstmt
> loop
>     ...
> end loop;

http://www.postgresql.org/docs/8.3/interactive/plpgsql-control-structures.html#PLPGSQL-RECORDS-ITERATING

If I am following the above right then  the: FOR target IN EXECUTE text_expression LOOP form is what you are
looking for.  I have not used variable substitution for this form, so you will need to test.

>
>
> Thanks in Advance for any help.

--
Adrian Klaver
adrian.klaver@gmail.com

pgsql-general by date:

Previous
From: "Gauthier, Dave"
Date:
Subject: plpgsql question
Next
From: Ray Stell
Date:
Subject: Re: pg_standby: How to check in which state the server is currently?