Execute a query passed by parameters to a function

Started by Yadira Lizama Mueover 16 years ago3 messagesgeneral
Jump to latest
#1Yadira Lizama Mue
ylizama@uci.cu

Hi,
I have a function which receive a parameters as text. This text is a query. I want to execute this query, but I don't know how. Can any one help me?
Regards,
Yadira

CREATE OR REPLACE FUNCTION myfunction(text)
RETURNS void AS
$BODY$
--I want execute the text I pass by parameters as a query.
$BODY$
LANGUAGE 'sql' VOLATILE

#2Thom Brown
thombrown@gmail.com
In reply to: Yadira Lizama Mue (#1)
Re: Execute a query passed by parameters to a function

2009/11/9 Yadira Lizama Mue <ylizama@uci.cu>:

Hi,
I have a function which receive a parameters as text. This text is a query. I want to execute this query, but I don't know how. Can any one help me?
Regards,
Yadira

CREATE OR REPLACE FUNCTION myfunction(text)
 RETURNS void AS
$BODY$
--I want execute the text I pass by parameters as a query.
$BODY$
 LANGUAGE 'sql' VOLATILE

You can use EXECUTE
(http://www.postgresql.org/docs/8.4/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN)

Out of curiosity, why would you wish to do such a thing?

Regards

Thom

#3Yadira Lizama Mue
ylizama@uci.cu
In reply to: Thom Brown (#2)
Re: Execute a query passed by parameters to a function

Thanks, it works..
The problem is that ..
I create dynamically the query and verified a few things inside the function before execute it.
Regards, Yadira

----- Mensaje original -----
De: "Thom Brown" <thombrown@gmail.com>
Para: "Yadira Lizama Mue" <ylizama@uci.cu>
CC: pgsql-general@postgresql.org
Enviados: Lunes, 9 de Noviembre 2009 17:00:28 GMT +01:00 Amsterdam / Berlín / Berna / Roma / Estocolmo / Viena
Asunto: Re: [GENERAL] Execute a query passed by parameters to a function

2009/11/9 Yadira Lizama Mue <ylizama@uci.cu>:

Hi,
I have a function which receive a parameters as text. This text is a query. I want to execute this query, but I don't know how. Can any one help me?
Regards,
Yadira

CREATE OR REPLACE FUNCTION myfunction(text)
 RETURNS void AS
$BODY$
--I want execute the text I pass by parameters as a query.
$BODY$
 LANGUAGE 'sql' VOLATILE

You can use EXECUTE
(http://www.postgresql.org/docs/8.4/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN)

Out of curiosity, why would you wish to do such a thing?

Regards

Thom

--

Yadira Lizama Mué
Universidad de las Ciencias Informáticas
Tel:. (837)2311
Apto:. 70104