Re: plpgsql question

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>
Subject: Re: plpgsql question
Date: 2011-12-05 15:11:44
Message-ID: 201112050711.45364.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ray Stell 2011-12-05 15:50:53 Re: pg_standby: How to check in which state the server is currently?
Previous Message Gauthier, Dave 2011-12-05 14:59:32 plpgsql question