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

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 (view raw or flat)
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

pdxpug by date

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

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