Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group