Re: Getting results from a dynamic query in PL/pgSQL

From: Johann Uhrmann <johann(dot)uhrmann(at)xpecto(dot)com>
To: "PostgreSQL - General (E-mail)" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Getting results from a dynamic query in PL/pgSQL
Date: 2003-01-29 15:11:41
Message-ID: 3E37EF2D.6080907@xpecto.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message pginfo 2003-01-29 15:19:18 Re: URGENT: referential integrity problem
Previous Message Alan Carbutt 2003-01-29 15:04:01 Firewalls and Postgres