Обсуждение: Destination table by variable?

Поиск
Список
Период
Сортировка

Destination table by variable?

От
"Erik Dahlstrand"
Дата:
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?

/Erik

Re: Destination table by variable?

От
Afton & Ray Still
Дата:
Hello Erik,
What front end are you using? I primarily use PHP, and this procedure is
simple. You just use string operations to put together your query however
you want. Use variables, math, concactanation, or ... .
The question you need to ask is: I'm using ______ as a front end and "I want
to choose the destination table by a variable." "Is it possible?
"
Ray
----- Original Message -----
From: "Erik Dahlstrand" <df03daer@ing.hj.se>
To: <pgsql-novice@postgresql.org>
Sent: Friday, March 18, 2005 7:35 AM
Subject: [NOVICE] Destination table by variable?


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?

/Erik

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to majordomo@postgresql.org so that your
      message can get through to the mailing list cleanly


--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.7.3 - Release Date: 3/15/2005




--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.7.3 - Release Date: 3/15/2005


Re: [despammed] Destination table by variable?

От
Andreas Kretschmer
Дата:
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    ===

Re: [despammed] Re: Destination table by variable?

От
Andreas Kretschmer
Дата:
am  18.03.2005, um  8:39:52 -0700 mailte Afton & Ray Still folgendes:
> Hello Erik,
> What front end are you using? I primarily use PHP, and this procedure is
> simple. You just use string operations to put together your query however

Please read again the question. Erik write a function in plpgsql.


> "
> Ray
> ----- Original Message ----- From: "Erik Dahlstrand" <df03daer@ing.hj.se>

Text first, and then the fullquote, is silly. And you break the thread.


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

Re: [despammed] Re: Destination table by variable?

От
Kretschmer Andreas
Дата:
Andreas Kretschmer <akretschmer@despammed.com> schrieb:
> Text first, and then the fullquote, is silly. And you break the thread.
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^

Sorry, this was not correct.


Andreas
--
Diese Message wurde erstellt mit freundlicher Unterstützung eines freilau-
fenden Pinguins aus artgerechter Freilandhaltung.   Er ist garantiert frei
von Micro$oft'schen Viren. (#97922 http://counter.li.org)     GPG 7F4584DA
Was, Sie wissen nicht, wo Kaufbach ist? Hier: N 51.05082°, E 13.56889° ;-)

Re: [despammed] Re: Destination table by variable?

От
Afton & Ray Still
Дата:
----- Original Message -----
From: "Andreas Kretschmer" <akretschmer@despammed.com>
To: <pgsql-novice@postgresql.org>
Sent: Friday, March 18, 2005 8:49 AM
Subject: Re: [despammed] Re: [NOVICE] Destination table by variable?


> am  18.03.2005, um  8:39:52 -0700 mailte Afton & Ray Still folgendes:
>> Hello Erik,
>> What front end are you using? I primarily use PHP, and this procedure is
>> simple. You just use string operations to put together your query however
>
> Please read again the question. Erik write a function in plpgsql.
>
>
>> "
>> Ray
>> ----- Original Message ----- From: "Erik Dahlstrand" <df03daer@ing.hj.se>
>
> Text first, and then the fullquote, is silly. And you break the thread.
>
>
> Andreas
> --
> Andreas Kretschmer    (Kontakt: siehe Header)
> Heynitz:  035242/47212,      D1: 0160/7141639
> GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
> ===    Schollglas Unternehmensgruppe    ===
>


Sorry,
Andreas is right, I missed those two little letters. (pl)
Ray




--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.7.3 - Release Date: 3/15/2005