Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aYfWh-0006s5-9q for pgsql-general@arkaria.postgresql.org; Wed, 24 Feb 2016 19:55:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aYfWg-0003Gn-Jy for pgsql-general@arkaria.postgresql.org; Wed, 24 Feb 2016 19:55:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aYfWf-0003Fc-BA for pgsql-general@postgresql.org; Wed, 24 Feb 2016 19:55:09 +0000 Received: from [66.111.4.26] (helo=out2-smtp.messagingengine.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aYfWc-0002to-Lo for pgsql-general@postgresql.org; Wed, 24 Feb 2016 19:55:08 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5F3B127A00 for ; Wed, 24 Feb 2016 14:54:44 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Wed, 24 Feb 2016 14:54:44 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=pFPFG9jICWRqEKqtx9QD+4hy504=; b=GeaqnV jBKuKQDWSorywoxq2QRtFzhpTm4djGZRvjJAldl3hvjd68NgJKqQSzliEJlm5pNu mmBvVi2NVYayXNusfoy0zWR8encqy7C8XiB9rSZVzA8zx3YC4fx1/Pj20ETGixDF 0ntLWw/YVVi7Vsoc915YipHkrg26VwYPid2fQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=pFPFG9jICWRqEKq tx9QD+4hy504=; b=o2bc6AsCqFUXNCng0/YeVhGxqEbXrW9RFamGWHDNzW0dbU/ pVG1Ab2moiMC8DBi3jPI3JQrak6wKIiFaKIpUIDait54mKZxETf/ZfjhxE2vxz5j 80Z0YPNeG6iBngXJxNBgU3tXySkWO5TQPE6ieP75RkOFfzMvMH5VQfPIdOV4= X-Sasl-enc: 8FwIrLCnJ3iopARB10ff99LllecJvyXXK85v7FEyYQSI 1456343684 Received: from killi.site (c-73-225-242-52.hsd1.wa.comcast.net [73.225.242.52]) by mail.messagingengine.com (Postfix) with ESMTPA id D9CE868016C; Wed, 24 Feb 2016 14:54:43 -0500 (EST) Subject: Re: "plan should not reference subplan's variable" when using row level security To: Adam Guthrie , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: <56CE0A82.3040307@aklaver.com> Date: Wed, 24 Feb 2016 11:54:42 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.26 (deferred) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org On 02/24/2016 09:51 AM, Adam Guthrie wrote: > Hi, > > Whilst trying to use row level security with a subquery in the USING > expression, I'm receiving an error "plan should not reference > subplan's variable" > > A simple sql file to reproduce: > > **** > > CREATE TABLE a ( > id INTEGER PRIMARY KEY > ); > > CREATE TABLE b ( > id INTEGER PRIMARY KEY, > a_id INTEGER, > text TEXT > ); > > CREATE POLICY a_select ON b FOR SELECT > USING ( EXISTS(SELECT FROM a WHERE a.id = b.a_id) ); > > ALTER TABLE b ENABLE ROW LEVEL SECURITY; > > INSERT INTO a (id) VALUES (1); > > INSERT INTO b (id, a_id, text) VALUES (1, 1, 'one'); > > GRANT ALL ON ALL TABLES IN SCHEMA public TO test; > > SET ROLE test; > > SELECT * FROM b; > > UPDATE b SET text = 'ONE' WHERE id = 1; > > **** > > gives error: > > psql:/tmp/test.sql:26: ERROR: plan should not reference subplan's variable > > Is this a bug or am I doing something wrong? I started to work through this when I realized the permissions/attributes of the role test are not shown. This seems to be important as the UPDATE example works if you run it immediately after: INSERT INTO b (id, a_id, text) VALUES (1, 1, 'one'); > > Any help much appreciated, > > Adam > > -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general