Re: how to pass tablename to a function

Поиск
Список
Период
Сортировка
От David G Johnston
Тема Re: how to pass tablename to a function
Дата
Msg-id 1409876608374-5817871.post@n5.nabble.com
обсуждение исходный текст
Ответ на how to pass tablename to a function  (A L. <e_toner@hotmail.com>)
Список pgsql-general
alecinvan wrote
> I like to pass the tablename to function but not using execute clause,
> here is my script
>
> [...]
>
> I want to pass the _tbl to the select query integrated in the unpacking(),
> how can I make it?

There is no way to perform a query with an unknown, at design time,
identifier without using EXECUTE.

The recommended way to do this is to use "format()" and dollar-quoting -
v9.1+ required:

v_qry := format(

$qry$
WITH [...]
SELECT id, func(...) FROM %I WHERE id [...]
$qry$

, _tbl

);

RETURN QUERY EXECUTE v_qry;

David J.




--
View this message in context:
http://postgresql.1045698.n5.nabble.com/how-to-pass-tablename-to-a-function-tp5817864p5817871.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: how to pass tablename to a function
Следующее
От: alecinvan
Дата:
Сообщение: how to pass tablename to a function