Thread: how to use variable for select query in pl/pgsql

how to use variable for select query in pl/pgsql

From
aBBISh
Date:
hello everybody,

i want use a variable to denote a table name in select query.

for example:

DECLARE
       table_message_data varchar;
       record_message_data record;
BEGIN
         table_message_data := prefix || 'message_data';

     select into record_message_data * from table_message_data;
END;

the "prefix" is the function input parameter,but i don't know how to use
the "table_message_data" in select query.


please tell me,thanks.

Re: how to use variable for select query in pl/pgsql

From
Michael Fuhr
Date:
On Wed, Aug 16, 2006 at 12:43:07PM +0800, aBBISh wrote:
> i want use a variable to denote a table name in select query.

See "Executing Dynamic Commands" in the PL/pgSQL documentation:

http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

--
Michael Fuhr