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 DB483D1B1CF for ; Tue, 20 Jul 2004 10:34:47 -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 98766-06 for ; Tue, 20 Jul 2004 13:34:42 +0000 (GMT) Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.195]) by svr1.postgresql.org (Postfix) with SMTP id CE14FD1B16A for ; Tue, 20 Jul 2004 10:34:37 -0300 (ADT) Received: by mproxy.gmail.com with SMTP id 73so656907rne for ; Tue, 20 Jul 2004 06:34:42 -0700 (PDT) Received: by 10.38.209.56 with SMTP id h56mr421120rng; Tue, 20 Jul 2004 06:34:20 -0700 (PDT) Message-ID: <7eeb33a04072006342b5d35a0@mail.gmail.com> Date: Tue, 20 Jul 2004 15:34:20 +0200 From: Lars Erik Thorsplass To: pgsql-sql@postgresql.org Subject: Stored procedures and "pseudo" fields.. In-Reply-To: <7eeb33a040720034319e036c6@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <7eeb33a040720034319e036c6@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/125 X-Sequence-Number: 18377 I also posted this to the general list, which might not have been a suitable forum. -- 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 don't. 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 number (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; This gives me a: ERROR: column "mode" does not exist If I remove the "mode > 0" logic, I get a result set with mode in it as expected. Why cant I do logic tests with the mode "field" ? I tried a different approach with a different error: SELECT * FROM objects, acl_check( objects.obid, 32 ) as mode WHERE mode > 0; This gives me a: ERROR: function expression in FROM may not refer to other relations of same query level. Here objecs.obid is unknown i suppose, but if I enter "10" as the first param using the mode "field" in a logic statement works. I would appreciate any hints to a workaround which would enable me to accomplish my scenario. Best regards, L.E.Thorsplass