pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ramakrishnan Muralidharan <ramakrishnanm@pervasive-postgres.com>
To: Federico Pedemonte <fepede@fastwebnet.it>
To: pgsql-sql@postgresql.org
Subject: Re: Multiple SRF parameters from query
Date: Wed, 1 Jun 2005 10:29:29 +0530
Message-ID: <02767D4600E59A4487233B23AEF5C59922C2B7@blrmail1.aus.pervasive.com> (raw)

Hi,

  I am not able to understand "Returning only one row", since 'aaa' having 2 rows and 'bbb' having 3 rows and what criteria single row should be returned. Please let me know the expected result and I will try to find out a solution for it.

  for set returning function the following link maybe helpful 
  http://techdocs.postgresql.org/guides/SetReturningFunctions

Regards,
R.Muralidharan


-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Federico Pedemonte
Sent: Tuesday, May 31, 2005 8:23 PM
To: pgsql-sql@postgresql.org
Subject: [SQL] Multiple SRF parameters from query


Hi All,

i'm having troubles trying to write a sql query using a Set Returning
Function.

I have a function foo (ID varchar) that returns a variable number of
records.
I have also a table (called Anagrafica) that contains a list of IDs to
be passed to the function foo.

As an example, just say that Anagrafica is like this:

Anagrafica

ID  | n
----+---
aaa | 1
bbb | 5
ccc | 9
ddd | 10
eee | 11

and foo returns this values 

select * from foo ('aaa')

a | b | c
--+---+---
1 | 2 | 3
5 | 9 | 1


select * from foo ('bbb')

a | b | c
--+---+---
4 | 0 | 0 
2 | 0 | 0
0 | 0 | 0 


what i would like to do is write an SQL query that looks something like
this (written in simplyfied-pseudo-sql)

SELECT FROM anagrafica
  WHERE n < 5 
    SELECT * FROM Foo (anagrafica.ID)	
  
and that gives as result a table that is the union of foo ('aaa') and
foo ('bbb')

a | b | c
--+---+---
1 | 2 | 3
5 | 9 | 1
4 | 0 | 0 
2 | 0 | 0
0 | 0 | 0 

I'm having success if foo returns only a row, but the problem is that
foo returns more than one.
I think i sould use a join but i couldn't find the right syntax for it.

I don't want to create a spefic PL/pgSQL function becase i need to have
freedom in selecting IDs from Anagrafica (the one i provided is just an
example, the real table is much more complex).

I would really appreciate any suggestion.

Best regards, 
	Federico.


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org



view thread (4+ messages)  latest in thread

Message-ID: <02767D4600E59A4487233B23AEF5C59922C2B7@blrmail1.aus.pervasive.com>
Permalink:  ../02767D4600E59A4487233B23AEF5C59922C2B7@blrmail1.aus.pervasive.com/
Also on:    postgresql.org/message-id/02767D4600E59A4487233B23AEF5C59922C2B7@blrmail1.aus.pervasive.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: ramakrishnanm@pervasive-postgres.com, fepede@fastwebnet.it
  Subject: Re: Multiple SRF parameters from query
  In-Reply-To: <02767D4600E59A4487233B23AEF5C59922C2B7@blrmail1.aus.pervasive.com>
  References: <02767D4600E59A4487233B23AEF5C59922C2B7@blrmail1.aus.pervasive.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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