Re: CASE eval issue

From: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
To: Aaron Burt <aaron(at)bavariati(dot)org>
Cc: pdxpug(at)postgresql(dot)org
Subject: Re: CASE eval issue
Date: 2011-10-18 22:42:10
Message-ID: 1D367375-8691-4E37-904C-A0845EC9C68C@kineticode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pdxpug

On Oct 18, 2011, at 3:31 PM, Aaron Burt wrote:

> Query:
> select id,
> case has_column_privilege('mytable', 'secure_column', 'SELECT')
> when FALSE then 'NA'
> else secure_column
> end as secure_column
> from mytable where id=12345;
>
> I get an "ERROR: permission denied for relation mytable" - even though it
> shouldn't be accessing the column if it doesn't have permissions.
>
> Even if I use a subselect instead of just the column name, it fails.
> But if I use a column that's permitted, no problem.

Try this:

select id,
case when has_column_privilege('mytable', 'secure_column', 'SELECT')
then 'NA'
else secure_column
end as secure_column
from mytable where id=12345;

HTH,

David

In response to

Responses

Browse pdxpug by date

  From Date Subject
Next Message Aaron Burt 2011-10-18 23:30:52 Re: CASE eval issue
Previous Message Aaron Burt 2011-10-18 22:31:31 CASE eval issue