Search Postgresql Archives

Re: plpgsql question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux