Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id AA05561BC24 for ; Fri, 27 Jul 2012 22:57:13 -0300 (ADT) Received: from mailout-de.gmx.net ([213.165.64.22]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1SuwHH-0005C4-BC for pgsql-sql@postgresql.org; Sat, 28 Jul 2012 01:57:12 +0000 Received: (qmail invoked by alias); 28 Jul 2012 01:56:57 -0000 Received: from p57BB77E8.dip.t-dialin.net (EHLO [192.168.1.11]) [87.187.119.232] by mail.gmx.net (mp036) with SMTP; 28 Jul 2012 03:56:57 +0200 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX199eGcQnGZ9jP+kIWYUOfJGcNg3BPXH9O7uzF6OfL U4i19CW8azUPtE Message-ID: <501346EC.2000305@gmx.net> Date: Sat, 28 Jul 2012 03:57:00 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: join against a function-result fails Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/33 X-Sequence-Number: 36770 Hi, I have a table with user ids and names. Another table describes some rights of those users and still another one describes who inherits rights from who. A function all_rights ( user_id ) calculates all rights of a user recursively and gives back a table with all userright_ids this user directly has or inherits of other users as ( user_id, userright_id ). Now I'd like to find all users who have the right 42. select user_id, user_name from users join all_rights ( user_id ) using ( user_id ) where userright_id = 42; won't work because the parameter user_id for the function all_rights() is unknown when the function gets called. Is there a way to do this?