Re: Passing table names to PL/PGSQL for SELECT/UPDATE/INSERT

From: Richard Huxton <dev(at)archonet(dot)com>
To: Gerald Gutierrez <pozix(at)home(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Passing table names to PL/PGSQL for SELECT/UPDATE/INSERT
Date: 2001-03-04 19:27:00
Message-ID: 3AA29705.B1D291D6@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Gerald Gutierrez wrote:
>
> I'd like to generalize my function. As per Richard Huxton's suggestion to
> create tables named after session ID (thanks Richard)s, I'd like to pass in
> some table names so that the algorithm can read from and write into tables
> that I specify as parameters to the function. Sometihng like:

Known limitation - sorry, should have made things clear.

> select dijkstra(inputtablename, outputtablename);
>
> I've tried typing the parameters as TEXT, and then just inserting $1 in the
> select (e.g. SELECT * from $1 ...) This doesn't work, nor did a number of
> other ways I tried.

Basically, I can think of 3 solutions. Bear in mind it's late here, I've
had a few drinks with dinner.

1. Use the EXECUTE statement in 7.1 to run the query
2. Use the EXECUTE statement to construct a custom function, one for
each session with the table hard-coded (you could also do this from the
application I'd guess)
3. Try pl/Tcl - I _think_ that lets you construct a dynamic query, but I
don't know TCL so can't say (it's supposed to be easy enough but I've
never got round to it).

HTH

- Richard Huxton

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gerald Gutierrez 2001-03-05 01:38:03 Re: Passing table names to PL/PGSQL for SELECT/UPDATE/INSERT
Previous Message Mitch Vincent 2001-03-04 18:37:11 Re: why the DB file size does not reduce when 'delete'the data in DB?