Skip site navigation (1) Skip section navigation (2)

Stored procedures and "pseudo" fields..

From: Lars Erik Thorsplass <thorsplass(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Stored procedures and "pseudo" fields..
Date: 2004-07-20 10:43:30
Message-ID: 7eeb33a040720034319e036c6@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-sql
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, <user_id> ) 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 resultset with mode in it as
expected. Why cant I do logic tests with the mode "field" ?


I tried a diffrent approach with a diffrent 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

Responses

pgsql-sql by date

Next:From: Markus BertheauDate: 2004-07-20 12:16:09
Subject: surrogate key or not?
Previous:From: Luis SousaDate: 2004-07-20 08:17:15
Subject: Re: Problem in age on a dates interval

pgsql-general by date

Next:From: Michael KleiserDate: 2004-07-20 11:01:22
Subject: Re: How to find records with the same field?
Previous:From: Joost KraaijeveldDate: 2004-07-20 10:37:50
Subject: Re: How to find records with the same field?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group