Re: Getting results from a dynamic query in PL/pgSQL - Mailing list pgsql-general

From Johann Uhrmann
Subject Re: Getting results from a dynamic query in PL/pgSQL
Date
Msg-id 3E37EF2D.6080907@xpecto.com
Whole thread Raw
In response to Re: Getting results from a dynamic query in PL/pgSQL  ("Patrick Fiche" <patrick.fiche@aqsacom.com>)
List pgsql-general
Patrick Fiche wrote:

> I'm not sure I really understood what you want...
>
> Here is perhaps what you need...
>
>
> CREATE TABLE t1
> (
>    col1 text
> );
>
> create or replace function foo(text) returns text as '
> DECLARE
>    colname ALIAS FOR $1;
>    sqlquery text;
>    result text;
> BEGIN
>    sqlquery := ''INSERT INTO t1 (col1 ) SELECT '' || colname || '' from
> toto'';
>    EXECUTE( sqlquery );
>
>    SELECT INTO result col1 FROM t1;
>    DELETE FROM t1;
>    RETURN result;
> END;
> ' language 'plpgsql';


Thank You Patrick. I consider Your solution as a workaround as it
uses a temporary table.

As far as I know, PL/Tcl directly supports dynamic table names - but
now I have difficulties to specify a literal value which should not
be treated as column name but as varchar-value.

Please see my other post for details.

Regards,

Hans


pgsql-general by date:

Previous
From: Tony Grant
Date:
Subject: Re: Firewalls and Postgres
Next
From: "Nigel J. Andrews"
Date:
Subject: Re: Firewalls and Postgres