Skip to content

Commit 25ad5a5

Browse files
committed
Improve documentation about JSONB array containment behavior.
Per gripe from Josh Berkus.
1 parent 4a50de1 commit 25ad5a5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

doc/src/sgml/json.sgml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ SELECT '"foo"'::jsonb @> '"foo"'::jsonb;
269269
-- The array on the right side is contained within the one on the left:
270270
SELECT '[1, 2, 3]'::jsonb @> '[1, 3]'::jsonb;
271271

272+
-- Order of array elements is not significant, so this is also true:
273+
SELECT '[1, 2, 3]'::jsonb @> '[3, 1]'::jsonb;
274+
275+
-- Duplicate array elements don't matter either:
276+
SELECT '[1, 2, 3]'::jsonb @> '[1, 2, 2]'::jsonb;
277+
272278
-- The object with a single pair on the right side is contained
273279
-- within the object on the left side:
274280
SELECT '{"product": "PostgreSQL", "version": 9.4, "jsonb":true}'::jsonb @> '{"version":9.4}'::jsonb;
@@ -288,8 +294,10 @@ SELECT '{"foo": {"bar": "baz"}}'::jsonb @> '{"bar": "baz"}'::jsonb; -- yields f
288294
The general principle is that the contained object must match the
289295
containing object as to structure and data contents, possibly after
290296
discarding some non-matching array elements or object key/value pairs
291-
from the containing object. However, the order of array elements is
292-
not significant when doing a containment match.
297+
from the containing object.
298+
But remember that the order of array elements is not significant when
299+
doing a containment match, and duplicate array elements are effectively
300+
considered only once.
293301
</para>
294302

295303
<para>

0 commit comments

Comments
 (0)