Re: PREPARE dynamic SQL in plpgsql
От | David G. Johnston |
---|---|
Тема | Re: PREPARE dynamic SQL in plpgsql |
Дата | |
Msg-id | CAKFQuwbEO8h7ivn2pFuSt9hwUmPjN7Mf+xub26UE+8UE7NxcHw@mail.gmail.com обсуждение исходный текст |
Ответ на | PREPARE dynamic SQL in plpgsql (Koichi Suzuki <koichi.szk@gmail.com>) |
Список | pgsql-hackers |
Hi,Does someone know how to prepare a synamic SQL statement in plpgsql?All the examples, PG documents describe only about preparing static SQL statement.
You might want to rephrase the question. From the pl/pgsql documentation:
"Note: The PL/pgSQL EXECUTE statement is not related to the EXECUTE SQL statement supported by the PostgreSQL server. The server's EXECUTE statement cannot be used directly within PL/pgSQL functions (and is not needed)."
So even if you could SQL-PREPARE you wouldn't be able to execute it.
The linked section describes how to construct and execute dynamic queries in pl/pgsql. The short answer is you create variable of type text and then EXECUTE it.
stmt := format('SELECT * FROM %i', in_tbl_name);
EXECUTE stmt [...]
David J.
В списке pgsql-hackers по дате отправления: