pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedPassing table names to PL/PGSQL for SELECT/UPDATE/INSERT
4+ messages / 3 participants
[nested] [flat]
* Passing table names to PL/PGSQL for SELECT/UPDATE/INSERT
@ 2001-03-04 04:32 Gerald Gutierrez <pozix@home.com>
0 siblings, 3 replies; 4+ messages in thread
From: Gerald Gutierrez @ 2001-03-04 04:32 UTC (permalink / raw)
To: pgsql-sql; +Cc: Richard Huxton <dev@archonet.com>
I've written my Dijkstra's algorithm in PL/PGSQL. It didn't turn out to be
a big deal at all actually, programming-wise. I understand execution speed
will be poor but it shouldn't be any slower than having something else,
like PHP or Java, execute logic and query the database.
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:
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.
How can this be done?
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Passing table names to PL/PGSQL for SELECT/UPDATE/INSERT
@ 2001-03-04 19:27 Richard Huxton <dev@archonet.com>
parent: Gerald Gutierrez <pozix@home.com>
2 siblings, 0 replies; 4+ messages in thread
From: Richard Huxton @ 2001-03-04 19:27 UTC (permalink / raw)
To: Gerald Gutierrez <pozix@home.com>; +Cc: 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Passing table names to PL/PGSQL for SELECT/UPDATE/INSERT
@ 2001-03-05 01:38 Gerald Gutierrez <pozix@home.com>
parent: Gerald Gutierrez <pozix@home.com>
2 siblings, 0 replies; 4+ messages in thread
From: Gerald Gutierrez @ 2001-03-05 01:38 UTC (permalink / raw)
To: josh@agliodbs.com; pgsql-sql
I've found the discussion to which you have referred:
http://www.postgresql.org/mhonarc/pgsql-sql/2001-02/msg00157.html
but was unable to find the documentation for the EXECUTE command. From the
discussion it seemed to me that doing an "INSERT" into a table of variable
name cannot be done now. It is unfortunate, but I guess nothing can be done
about it now.
At 04:40 PM 3/4/2001 -0800, you wrote:
>Mr. Gutierrez:
>
> The EXECUTE command is what you need. Please see the development
>documentation, and the list archives for January-Early Feb.
>
> -Josh Berkus
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Passing table names to PL/PGSQL for SELECT/UPDATE/INSERT
@ 2001-03-05 18:23 Jie Liang <jliang@ipinc.com>
parent: Gerald Gutierrez <pozix@home.com>
2 siblings, 0 replies; 4+ messages in thread
From: Jie Liang @ 2001-03-05 18:23 UTC (permalink / raw)
To: Gerald Gutierrez <pozix@home.com>; +Cc: pgsql-sql@postgresql.org, Richard Huxton <dev@archonet.com>
Unfortunately, PL/PGSQL cannot pass table name.
I have same problem, only thing I can do is pass an integer, then use IF
.. THEN .. ELSE .. END IF;
Jie LIANG
St. Bernard Software
10350 Science Center Drive
Suite 100, San Diego, CA 92121
Office:(858)320-4873
jliang@ipinc.com
www.stbernard.com
www.ipinc.com
On Sat, 3 Mar 2001, Gerald Gutierrez wrote:
>
> I've written my Dijkstra's algorithm in PL/PGSQL. It didn't turn out to be
> a big deal at all actually, programming-wise. I understand execution speed
> will be poor but it shouldn't be any slower than having something else,
> like PHP or Java, execute logic and query the database.
>
> 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:
>
> 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.
>
> How can this be done?
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2001-03-05 18:23 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-04 04:32 Passing table names to PL/PGSQL for SELECT/UPDATE/INSERT Gerald Gutierrez <pozix@home.com>
2001-03-04 19:27 ` Richard Huxton <dev@archonet.com>
2001-03-05 01:38 ` Gerald Gutierrez <pozix@home.com>
2001-03-05 18:23 ` Jie Liang <jliang@ipinc.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox