Re: Execute a query passed by parameters to a function

From: Thom Brown <thombrown(at)gmail(dot)com>
To: Yadira Lizama Mue <ylizama(at)uci(dot)cu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Execute a query passed by parameters to a function
Date: 2009-11-09 16:00:28
Message-ID: bddc86150911090800y61c5a4c0je007f712b7609f2c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2009/11/9 Yadira Lizama Mue <ylizama(at)uci(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Barnes 2009-11-09 16:04:24 Re: Looking for a script that performs full online backup of postgres in archive mode
Previous Message Alexandra Roy 2009-11-09 15:53:31 Re: PostgreSQL 8.3.8 on AIX5.3 : compilation failed