pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: marcus@cockroachlabs.com
Subject: BUG #17873: Empty JSONB array is ordered before all other JSONB values
Date: Mon, 27 Mar 2023 19:17:07 +0000
Message-ID: <17873-826fdc8bbcace4f1@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      17873
Logged by:          Marcus Gartner
Email address:      marcus@cockroachlabs.com
PostgreSQL version: 14.6
Operating system:   macOS 13.2.1
Description:        

The JSONB Indexing documentation (here:
https://www.postgresql.org/docs/14/datatype-json.html#JSON-INDEXING) states
that:

"The btree ordering for jsonb datums is seldom of great interest, but for
completeness it is:
Object > Array > Boolean > Number > String > Null"

However, the empty JSONB array value does comply with this ordering as it is
less than all other JSONB values, as far as I
can tell.

SELECT '[]'::JSONB < j::JSONB
FROM (VALUES
  ('null'),
  ('"a"'),
  ('1'),
  ('[1]'),
  ('{}')
) v(j);
 ?column?
----------
 t
 t
 t
 t
 t
(5 rows)

Is this a bug in the B-tree ordering of JSONB values? I could not find any
notes in the source code or test cases that explain this
special case for empty JSONB arrays.

Thanks,
Marcus



Message-ID: <17873-826fdc8bbcace4f1@postgresql.org>
Permalink:  ../17873-826fdc8bbcace4f1@postgresql.org/
Also on:    postgresql.org/message-id/17873-826fdc8bbcace4f1@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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, marcus@cockroachlabs.com
  Subject: Re: BUG #17873: Empty JSONB array is ordered before all other JSONB values
  In-Reply-To: <17873-826fdc8bbcace4f1@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