Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 6A498632202 for ; Mon, 1 Mar 2010 09:39:08 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 32321-02 for ; Mon, 1 Mar 2010 13:38:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from relay.pcl-ipout02.plus.net (relay.pcl-ipout02.plus.net [212.159.7.100]) by mail.postgresql.org (Postfix) with ESMTP id D796162DBD2 for ; Mon, 1 Mar 2010 09:38:57 -0400 (AST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAMRSi0vUnw4U/2dsb2JhbACbD3O5GoR7BA Received: from pih-relay08.plus.net ([212.159.14.20]) by relay.pcl-ipout02.plus.net with ESMTP; 01 Mar 2010 13:38:55 +0000 Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay08.plus.net with esmtp (Exim) id 1Nm5pm-0007NI-Q5; Mon, 01 Mar 2010 13:38:55 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTPA id 7342C418048; Mon, 1 Mar 2010 13:38:54 +0000 (GMT) Message-ID: <4B8BC36E.4040007@archonet.com> Date: Mon, 01 Mar 2010 13:38:54 +0000 From: Richard Huxton User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9pre) Gecko/20100217 Lightning/1.0b1 Shredder/3.0.3pre MIME-Version: 1.0 To: rawi CC: pgsql-sql@postgresql.org Subject: Re: kind of RULE on SELECT depending on existence of a WHERE condition References: <27741669.post@talk.nabble.com> <4B8B983B.4080205@archonet.com> <27742718.post@talk.nabble.com> In-Reply-To: <27742718.post@talk.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: deb3fe0c5004b4ecd32475d3bace36fe X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.74 tagged_above=-10 required=5 tests=BAYES_20=-0.74 X-Spam-Level: X-Archive-Number: 201003/5 X-Sequence-Number: 33712 On 01/03/10 12:16, rawi wrote: > >> Not quite the way you suggest. You could build a series of views with >> the WHERE conditions built in to them, and grant permissions on those >> though. > > Thank you very much for your help. > > Unfortunately is this not what I hoped... > The permissions will be granted dynamic by the application out of the > user-records and expressed in the WHERE flags. > I'll need another approach... You could write a set-returning function that takes either: 1. A list of conditions 2. The text for a WHERE clause If it gets no conditions or a blank string, it returns nothing. You will need to create the function with SECURITY DEFINER permissions, as a user who can read from the table. Make sure the application cannot read from the table and has to use the function. -- Richard Huxton Archonet Ltd