Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VWnGb-0000Ys-3r for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Oct 2013 13:05:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VWnGZ-0002QC-MD for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Oct 2013 13:05:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VWX0J-0004QL-4w for pgsql-bugs@postgresql.org; Wed, 16 Oct 2013 19:43:35 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VWX0F-0004hD-SK for pgsql-bugs@postgresql.org; Wed, 16 Oct 2013 19:43:34 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by mahout.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VWX0D-0008VY-II for pgsql-bugs@postgresql.org; Wed, 16 Oct 2013 19:43:30 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.80) (envelope-from ) id 1VWX07-0005Yy-Qh for pgsql-bugs@postgresql.org; Wed, 16 Oct 2013 19:43:23 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: BUG #8533: JSON error caused by optimisation To: pgsql-bugs@postgresql.org From: m@pplcast.com Message-Id: Date: Wed, 16 Oct 2013 19:43:23 +0000 X-Pg-Spam-Score: -2.4 (--) 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 The following bug has been logged on the website: Bug reference: 8533 Logged by: Mike Email address: m@pplcast.com PostgreSQL version: 9.3.1 Operating system: all Description: Not sure if bug or feature, but the query below without the "offset 0" fails with "ERROR: cannot extract field from a non-object", while the one with succeeds as intended. Please excuse the messiness. =# explain select aaa->'bbb'->'ccc'->'ddd'->>1, aaa->'bbb'->'ccc' from (select aaa from yyy where not json_isarray(aaa->'bbb'->'ccc')) _(aaa) where (aaa->'bbb'->'ccc'->'ddd'->>1) = 'eee'; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Seq Scan on yyy (cost=0.00..3502.00 rows=32 width=32) Filter: ((((((aaa -> 'bbb'::text) -> 'ccc'::text) -> 'ddd'::text) ->> 1) = 'eee'::text) AND (NOT json_isarray(((aaa -> 'bbb'::text) -> 'ccc'::text)))) (2 rows) =# explain select aaa->'bbb'->'ccc'->'ddd'->>1, aaa->'bbb'->'ccc' from (select aaa from yyy where not json_isarray(aaa->'bbb'->'ccc') offset 0) _(aaa) where (aaa->'bbb'->'ccc'->'ddd'->>1) = 'eee'; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------- Subquery Scan on _ (cost=0.00..3526.31 rows=32 width=32) Filter: (((((_.aaa -> 'bbb'::text) -> 'ccc'::text) -> 'ddd'::text) ->> 1) = 'eee'::text) -> Seq Scan on yyy (cost=0.00..3379.92 rows=6485 width=32) Filter: (NOT json_isarray(((aaa -> 'bbb'::text) -> 'ccc'::text))) (4 rows) CREATE OR REPLACE FUNCTION json_isarray(obj json) RETURNS bool AS $$ BEGIN PERFORM json_array_elements(obj); RETURN true; EXCEPTION WHEN invalid_parameter_value THEN RETURN false; END; $$ LANGUAGE plpgsql IMMUTABLE; -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs