Search Postgresql Archives

Re: PL/PGSQL - dynamic variable names

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

 




On 06/28/2011 06:29 PM, Ben Carbery wrote:
> Hi,
>
> I am trying to EXECUTE .. INTO a variable that I want to be
> dynamically named.
>
>     stuff := '{a,b,c,d}';
>
>     FOR i IN 1..4 LOOP
>         thing := stuff[i];
>
>         -- stuff_a, stuff_b etc are functions - substitution works here
>         exec_string := 'SELECT stuff_' || thing || '(''' || arg1 ||
> ''',''' || arg2 || ''');';
>
>         -- thing not substituted
>         -- value of thing above is replaced on each iteration rather
> than assigning result into variables a,b,c,d
>         EXECUTE exec_string INTO thing;
>
>     END LOOP;
>
> The variable names always seems to be interpreted literally though. Is
> there a way to make this work in PL/PGSQL?
>
> Of course it would be nice if EXECUTE supported 'SELECT INTO' :)
>
> cheers,
>
> Ben

Hm, "a" isn't a variable,it's the value of stuff[1].  Did you try
declaring a,b,c,d as the return type of the respective functions?

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