X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A02DCD1B1E0 for ; Tue, 20 Jul 2004 12:44:05 -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 69281-06 for ; Tue, 20 Jul 2004 15:43:57 +0000 (GMT) Received: from mpls-qmqp-04.inet.qwest.net (mpls-qmqp-04.inet.qwest.net [63.231.195.115]) by svr1.postgresql.org (Postfix) with SMTP id 67C20D1B16E for ; Tue, 20 Jul 2004 12:43:55 -0300 (ADT) Received: (qmail 22908 invoked by uid 0); 20 Jul 2004 15:43:55 -0000 Received: from mpls-pop-08.inet.qwest.net (63.231.195.8) by mpls-qmqp-04.inet.qwest.net with QMQP; 20 Jul 2004 15:43:55 -0000 Received: from 63-227-127-37.dnvr.qwest.net (HELO ?10.0.0.2?) (63.227.127.37) by mpls-pop-08.inet.qwest.net with SMTP; 20 Jul 2004 15:43:54 -0000 Date: Tue, 20 Jul 2004 09:45:06 -0600 Message-Id: <1090338306.709.25.camel@localhost.localdomain> From: "Scott Marlowe" To: "Lars Erik Thorsplass" Cc: pgsql-general@postgresql.org Subject: Re: Stored procedures and "pseudo" fields.. In-Reply-To: <7eeb33a040720034319e036c6@mail.gmail.com> References: <7eeb33a040720034319e036c6@mail.gmail.com> Content-Type: text/plain Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200407/617 X-Sequence-Number: 63216 On Tue, 2004-07-20 at 04:43, Lars Erik Thorsplass wrote: > I have recently ventured into the exciting world of stored procedures, > but I have now become lost. > > Background: > > Am currently working on access control in a web application. My goal > is to process access control on the SQL level. This way if a row is in > the result set, you have access to it, if not, you dont. > > > Problem: > > My stored procedure "acl_check()" takes two integers as parameters. > Param1 is the object id to check acl on, Param 2 is the object id of > the user currently using the system. The procedure returns a positive > numer (1 or 3 ) if you have some kind of access to the object. As one > might understand I want the returned value from the acl_check() > procedure to be a part of the result set. > > Kinda like this: > > SELECT *, acl_check( objects.obid, ) AS mode FROM objects > WHERE mode > 0; Here's the problem. In order to do the select, the query first needs to run the where clause. I.e.: select a as test from table where a > 50; works, but select a as test from table where test > 50; fails. The reason is that when the where clause fires first, there IS no test yet, as it hasn't been materialized. what you need to do is: select custom_function(a,b) from table where custom_function(a,b) > 0;