pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Query with Parameters
3+ messages / 3 participants
[nested] [flat]

* Query with Parameters
@ 2002-02-06 16:53  Evil Azrael <evilazrael@evilazrael.de>
  0 siblings, 2 replies; 3+ messages in thread

From: Evil Azrael @ 2002-02-06 16:53 UTC (permalink / raw)
  To: pgsql-sql

Hello!

I hope this question was not asked before.

What i need is SELECT with parameters. Afaik Views don´t take
parameters and functions can´t return multiple tuples. Am i right? Or
have i overseen something in the documentation or in the 1.8 million
pages about PgSQL which Google.com knows?

My main problem is that i have a complex query in which very often the
same tables and fields are being used. A simple SQL-function would be
very handy, but how do i return multiple records at the same time?

as a simple example, is a function like this possible?
SELECT funktion('field','table');
where funktion is implemented like this :
SELECT $1 FROM $2;


Thanks for any answer in advance

Christoph Nelles
evilazrael@evilazrael.de


-- 
Mit freundlichen Grüssen
Evil Azrael                            mailto:evilazrael@evilazrael.de




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Query with Parameters
@ 2002-02-06 17:57  Ian Barwick <barwick@gmx.net>
  parent: Evil Azrael <evilazrael@evilazrael.de>
  1 sibling, 0 replies; 3+ messages in thread

From: Ian Barwick @ 2002-02-06 17:57 UTC (permalink / raw)
  To: Evil Azrael <evilazrael@evilazrael.de>; pgsql-sql

On Wednesday 06 February 2002 17:53, Evil Azrael wrote:
> Hello!
>
> I hope this question was not asked before.
>
> What i need is SELECT with parameters. Afaik Views don´t take
> parameters and functions can´t return multiple tuples. Am i right? 

Nope, at least as far as VIEWs go.

> Or
> have i overseen something in the documentation or in the 1.8 million
> pages about PgSQL which Google.com knows?

See for example:

http://www.commandprompt.com/ppbook/index.lxp?lxpwrap=x7379%2ehtm

hth

Ian Barwick



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Query with Parameters
@ 2002-02-06 19:24  Jeff Eckermann <jeff_eckermann@yahoo.com>
  parent: Evil Azrael <evilazrael@evilazrael.de>
  1 sibling, 0 replies; 3+ messages in thread

From: Jeff Eckermann @ 2002-02-06 19:24 UTC (permalink / raw)
  To: Evil Azrael <evilazrael@evilazrael.de>; pgsql-sql

One possible way, from the psql command line:
  \set field some_field
  \set table some_table
  \i myscript
where "myscript" contains:
  select :field from :table;
You can do this from a script by calling psql with the
-f and -v options.  Check the psql man page (or the
docs) for more information.

Alternatively, you could try a function: the field and
table names can be assigned dynamically using EXECUTE.
 You could then populate a temporary table with the
results, and fetch those with a separate SELECT
statement (this gets around the inability to return
resultsets directly from the function).

--- Evil Azrael <evilazrael@evilazrael.de> wrote:
> Hello!
> 
> I hope this question was not asked before.
> 
> What i need is SELECT with parameters. Afaik Views
> don´t take
> parameters and functions can´t return multiple
> tuples. Am i right? Or
> have i overseen something in the documentation or in
> the 1.8 million
> pages about PgSQL which Google.com knows?
> 
> My main problem is that i have a complex query in
> which very often the
> same tables and fields are being used. A simple
> SQL-function would be
> very handy, but how do i return multiple records at
> the same time?
> 
> as a simple example, is a function like this
> possible?
> SELECT funktion('field','table');
> where funktion is implemented like this :
> SELECT $1 FROM $2;
> 
> 
> Thanks for any answer in advance
> 
> Christoph Nelles
> evilazrael@evilazrael.de
> 
> 
> -- 
> Mit freundlichen Grüssen
> Evil Azrael                           
> mailto:evilazrael@evilazrael.de
> 
> 
> ---------------------------(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


__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2002-02-06 19:24 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-06 16:53 Query with Parameters Evil Azrael <evilazrael@evilazrael.de>
2002-02-06 17:57 ` Ian Barwick <barwick@gmx.net>
2002-02-06 19:24 ` Jeff Eckermann <jeff_eckermann@yahoo.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