Re: [despammed] Destination table by variable?

From: Andreas Kretschmer <akretschmer(at)despammed(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: [despammed] Destination table by variable?
Date: 2005-03-18 15:45:26
Message-ID: 20050318154526.GG23980@webserv.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 ===

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Andreas Kretschmer 2005-03-18 15:49:08 Re: [despammed] Re: Destination table by variable?
Previous Message Afton & Ray Still 2005-03-18 15:39:52 Re: Destination table by variable?