X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C57785294D for ; Tue, 31 May 2005 11:53:33 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49197-09 for ; Tue, 31 May 2005 14:53:29 +0000 (GMT) Received: from mbox.arpal.org (unknown [83.103.67.134]) by svr1.postgresql.org (Postfix) with ESMTP id 614A95293C for ; Tue, 31 May 2005 11:53:27 -0300 (ADT) Received: (from root@localhost) by mbox.arpal.org (8.12.3/8.12.3/Debian -4) id j4VErU0H003016 for pgsql-sql@postgresql.org; Tue, 31 May 2005 16:53:30 +0200 Received: from protciv14.cmirl.arpal.org (protciv14.cmirl.arpal.org [10.24.4.214]) by mbox.arpal.org (8.12.3/8.12.3/Debian -4) with ESMTP id j4VErSAt002988 for ; Tue, 31 May 2005 16:53:28 +0200 Subject: Multiple SRF parameters from query From: Federico Pedemonte To: pgsql-sql@postgresql.org Content-Type: text/plain Date: Tue, 31 May 2005 16:52:52 +0200 Message-Id: <1117551172.895.46.camel@protciv14.cmirl.arpal.org> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 Content-Transfer-Encoding: 7bit X-scanner: scanned by Inflex 1.0.12.3 - (http://pldaniels.com/inflex/) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.87 tagged_above=0 required=5 tests=DNS_FROM_AHBL_RHSBL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, FORGED_RCVD_HELO X-Spam-Level: * X-Archive-Number: 200505/240 X-Sequence-Number: 21553 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.