diff options
author | Alvaro Herrera | 2023-03-31 20:34:04 +0000 |
---|---|---|
committer | Alvaro Herrera | 2023-03-31 20:34:04 +0000 |
commit | 6ee30209a6f161d0a267a33f090c70c579c87c00 (patch) | |
tree | eda2b3a9f0a61f3fc484819b39abf1eb130e0d88 /doc/src | |
parent | a2a0c7c29e47f39da905577659e66b0086b769cc (diff) |
SQL/JSON: support the IS JSON predicate
This patch introduces the SQL standard IS JSON predicate. It operates
on text and bytea values representing JSON, as well as on the json and
jsonb types. Each test has IS and IS NOT variants and supports a WITH
UNIQUE KEYS flag. The tests are:
IS JSON [VALUE]
IS JSON ARRAY
IS JSON OBJECT
IS JSON SCALAR
These should be self-explanatory.
The WITH UNIQUE KEYS flag makes these return false when duplicate keys
exist in any object within the value, not necessarily directly contained
in the outermost object.
Author: Nikita Glukhov <[email protected]>
Author: Teodor Sigaev <[email protected]>
Author: Oleg Bartunov <[email protected]>
Author: Alexander Korotkov <[email protected]>
Author: Amit Langote <[email protected]>
Author: Andrew Dunstan <[email protected]>
Reviewers have included (in no particular order) Andres Freund, Alexander
Korotkov, Pavel Stehule, Andrew Alsup, Erik Rijkers, Zihong Yu,
Himanshu Upadhyaya, Daniel Gustafsson, Justin Pryzby.
Discussion: https://postgr.es/m/CAF4Au4w2x-5LTnN_bxky-mq4=WOqsGsxSpENCzHRAzSnEd8+WQ@mail.gmail.com
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/abd9b83b-aa66-f230-3d6d-734817f0995d%40postgresql.org
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/func.sgml | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 38e7f46760..918a492234 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -16006,6 +16006,86 @@ table2-mapping </table> <para> + <xref linkend="functions-sqljson-misc" /> details SQL/JSON + facilities for testing JSON. + </para> + + <table id="functions-sqljson-misc"> + <title>SQL/JSON Testing Functions</title> + <tgroup cols="1"> + <thead> + <row> + <entry role="func_table_entry"><para role="func_signature"> + Function signature + </para> + <para> + Description + </para> + <para> + Example(s) + </para></entry> + </row> + </thead> + <tbody> + <row> + <entry role="func_table_entry"><para role="func_signature"> + <indexterm><primary>IS JSON</primary></indexterm> + <replaceable>expression</replaceable> <literal>IS</literal> <optional> <literal>NOT</literal> </optional> <literal>JSON</literal> + <optional> { <literal>VALUE</literal> | <literal>SCALAR</literal> | <literal>ARRAY</literal> | <literal>OBJECT</literal> } </optional> + <optional> { <literal>WITH</literal> | <literal>WITHOUT</literal> } <literal>UNIQUE</literal> <optional> <literal>KEYS</literal> </optional> </optional> + </para> + <para> + This predicate tests whether <replaceable>expression</replaceable> can be + parsed as JSON, possibly of a specified type. + If <literal>SCALAR</literal> or <literal>ARRAY</literal> or + <literal>OBJECT</literal> is specified, the + test is whether or not the JSON is of that particular type. If + <literal>WITH UNIQUE KEYS</literal> is specified, then any object in the + <replaceable>expression</replaceable> is also tested to see if it + has duplicate keys. + </para> + <para> +<programlisting> +SELECT js, + js IS JSON "json?", + js IS JSON SCALAR "scalar?", + js IS JSON OBJECT "object?", + js IS JSON ARRAY "array?" +FROM (VALUES + ('123'), ('"abc"'), ('{"a": "b"}'), ('[1,2]'),('abc')) foo(js); + js | json? | scalar? | object? | array? +------------+-------+---------+---------+-------- + 123 | t | t | f | f + "abc" | t | t | f | f + {"a": "b"} | t | f | t | f + [1,2] | t | f | f | t + abc | f | f | f | f +</programlisting> + </para> + <para> +<programlisting> +SELECT js, + js IS JSON OBJECT "object?", + js IS JSON ARRAY "array?", + js IS JSON ARRAY WITH UNIQUE KEYS "array w. UK?", + js IS JSON ARRAY WITHOUT UNIQUE KEYS "array w/o UK?" +FROM (VALUES ('[{"a":"1"}, + {"b":"2","b":"3"}]')) foo(js); +-[ RECORD 1 ]-+-------------------- +js | [{"a":"1"}, + + | {"b":"2","b":"3"}] +object? | f +array? | t +array w. UK? | f +array w/o UK? | t +</programlisting> + </para></entry> + </row> + </tbody> + </tgroup> + </table> + + <para> <xref linkend="functions-json-processing-table"/> shows the functions that are available for processing <type>json</type> and <type>jsonb</type> values. </para> |