pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: m@pplcast.com
To: pgsql-bugs@postgresql.org
Subject: BUG #8533: JSON error caused by optimisation
Date: Wed, 16 Oct 2013 19:43:23 +0000
Message-ID: <E1VWX07-0005Yy-Qh@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (2+ messages)  latest in thread

Message-ID: <E1VWX07-0005Yy-Qh@wrigleys.postgresql.org>
Permalink:  ../E1VWX07-0005Yy-Qh@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1VWX07-0005Yy-Qh@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: m@pplcast.com
  Subject: Re: BUG #8533: JSON error caused by optimisation
  In-Reply-To: <E1VWX07-0005Yy-Qh@wrigleys.postgresql.org>
  References: <E1VWX07-0005Yy-Qh@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox