Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VTckz-0006Ic-K2 for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Oct 2013 19:15:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VTckz-0006md-1o for pgsql-bugs@arkaria.postgresql.org; Tue, 08 Oct 2013 19:15:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VTcky-0006mW-4p for pgsql-bugs@postgresql.org; Tue, 08 Oct 2013 19:15:44 +0000 Received: from sam.nabble.com ([216.139.236.26]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VTcku-0005s1-K8 for pgsql-bugs@postgresql.org; Tue, 08 Oct 2013 19:15:43 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1VTckt-0003Q0-Le for pgsql-bugs@postgresql.org; Tue, 08 Oct 2013 12:15:39 -0700 Date: Tue, 8 Oct 2013 12:15:39 -0700 (PDT) From: David Johnston To: pgsql-bugs@postgresql.org Message-ID: <1381259739660-5773757.post@n5.nabble.com> In-Reply-To: <20131008190200.GE2706@tamriel.snowman.net> References: <20131008190200.GE2706@tamriel.snowman.net> Subject: Re: BUG #8512: Can't use columns I can't read in the where clause of a select MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 1.8 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Stephen Frost wrote > * > kurt@ > ( > kurt@ > ) wrote: >> Allows SELECT from any column, or the specific columns listed, of the >> specified table, view, or sequence. Also allows the use of COPY TO. This >> privilege is also needed to reference existing column values in UPDATE or >> DELETE. >> >> >> I read that as "SELECT field1 from table where field2 = 1" should work if >> I >> have grant select(field1), but not on field2. I'm getting a "permission >> denied". If I remove the where clause it of course works. > > You have to have SELECT rights on a column to be able to use it in a > conditional (eg: with WHERE). > >> I'm not sure if the behaviour is expected or not. Maybe I'm reading the >> documentation wrong, or maybe the documentation is just wrong. Could >> someone please clarify? > > It's expected. The documentation could perhaps be improved, but the > second sentence ("This privilege is also needed..") is intended to cover > the case where the column is being referred to *anywhere* in the query, > basically, and that applies to SELECT as much as UPDATE or DELETE. "SELECT": read the current value "UPDATE": cause the current value to be changed (does not require knowing the existing value) "DELETE": cause the current value (indirectly via row removal) to be removed (does not require knowing the existing value) A where clause requires that the user can know the current value in the field Within a SELECT statement there is no permissions distinction between the different sub-clauses (e.g., ORDER BY, GROUP BY, WHERE, select-list) since in any of these cases it is the current value of a column that is needed. So "SELECT" is read as being a top-level (as are UPDATE and DELETE) - and as Stephen said because WHERE can be part of UPDATE and DELETE the additional comment is made that WHERE in those contexts require "SELECT-like" privileges if the column is used there. But not if the column only exists as a target-column. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-8512-Can-t-use-columns-I-can-t-read-in-the-where-clause-of-a-select-tp5773752p5773757.html Sent from the PostgreSQL - bugs mailing list archive at Nabble.com. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs