Re: [despammed] Destination table by variable? - Mailing list pgsql-novice

From Andreas Kretschmer
Subject Re: [despammed] Destination table by variable?
Date
Msg-id 20050318154526.GG23980@webserv.wug-glas.de
Whole thread Raw
In response to Destination table by variable?  ("Erik Dahlstrand" <df03daer@ing.hj.se>)
List pgsql-novice
am  18.03.2005, um 15:35:37 +0100 mailte Erik Dahlstrand folgendes:
> Hi!
>
> I want to choose the destination table by a variable. Something like this:
>
> CREATE FUNCTION insert_this(int4, varchar, varchar) RETURNS void AS $$
>     DECLARE
>         destTable text;
>     BEGIN
>         SELECT INTO destTable get_table_name($1);
>
>         INSERT INTO destTable VALUES ($2, $3);
>     END;
> $$ LANGUAGE plpgsql;
>
> Is it possible?

Yes, you can build your SQL as string and then execute this with
EXECUTE.
http://www.postgresql.org/docs/7.4/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN


Andreas
--
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47212,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===    Schollglas Unternehmensgruppe    ===

pgsql-novice by date:

Previous
From: Afton & Ray Still
Date:
Subject: Re: Destination table by variable?
Next
From: Andreas Kretschmer
Date:
Subject: Re: [despammed] Re: Destination table by variable?