mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
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 <n.gluhov@postgrespro.ru> Author: Teodor Sigaev <teodor@sigaev.ru> Author: Oleg Bartunov <obartunov@gmail.com> Author: Alexander Korotkov <aekorotkov@gmail.com> Author: Amit Langote <amitlangote09@gmail.com> Author: Andrew Dunstan <andrew@dunslane.net> 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/cd0bb935-0158-78a7-08b5-904886deac4b@postgrespro.ru Discussion: https://postgr.es/m/20220616233130.rparivafipt6doj3@alap3.anarazel.de Discussion: https://postgr.es/m/abd9b83b-aa66-f230-3d6d-734817f0995d%40postgresql.org
This commit is contained in:
@ -100,103 +100,132 @@ main ()
|
||||
{
|
||||
/* exec sql begin declare section */
|
||||
|
||||
|
||||
|
||||
#line 12 "sqljson.pgc"
|
||||
char json [ 1024 ] ;
|
||||
/* exec sql end declare section */
|
||||
|
||||
#line 13 "sqljson.pgc"
|
||||
bool is_json [ 8 ] ;
|
||||
/* exec sql end declare section */
|
||||
#line 14 "sqljson.pgc"
|
||||
|
||||
|
||||
ECPGdebug (1, stderr);
|
||||
|
||||
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
|
||||
#line 17 "sqljson.pgc"
|
||||
#line 18 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 17 "sqljson.pgc"
|
||||
#line 18 "sqljson.pgc"
|
||||
|
||||
{ ECPGsetcommit(__LINE__, "on", NULL);
|
||||
#line 18 "sqljson.pgc"
|
||||
#line 19 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 18 "sqljson.pgc"
|
||||
#line 19 "sqljson.pgc"
|
||||
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_object ( returning text )", ECPGt_EOIT,
|
||||
ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
||||
#line 20 "sqljson.pgc"
|
||||
#line 21 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 20 "sqljson.pgc"
|
||||
#line 21 "sqljson.pgc"
|
||||
|
||||
printf("Found json=%s\n", json);
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_object ( returning text format json )", ECPGt_EOIT,
|
||||
ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
||||
#line 23 "sqljson.pgc"
|
||||
#line 24 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 23 "sqljson.pgc"
|
||||
#line 24 "sqljson.pgc"
|
||||
|
||||
printf("Found json=%s\n", json);
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_array ( returning jsonb )", ECPGt_EOIT,
|
||||
ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
||||
#line 26 "sqljson.pgc"
|
||||
#line 27 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 26 "sqljson.pgc"
|
||||
#line 27 "sqljson.pgc"
|
||||
|
||||
printf("Found json=%s\n", json);
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_array ( returning jsonb format json )", ECPGt_EOIT,
|
||||
ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
||||
#line 29 "sqljson.pgc"
|
||||
#line 30 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 29 "sqljson.pgc"
|
||||
#line 30 "sqljson.pgc"
|
||||
|
||||
printf("Found json=%s\n", json);
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_object ( 1 : 1 , '1' : null with unique )", ECPGt_EOIT,
|
||||
ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
||||
#line 32 "sqljson.pgc"
|
||||
#line 33 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 32 "sqljson.pgc"
|
||||
#line 33 "sqljson.pgc"
|
||||
|
||||
// error
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_object ( 1 : 1 , '2' : null , 1 : '2' absent on null without unique keys )", ECPGt_EOIT,
|
||||
ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
||||
#line 35 "sqljson.pgc"
|
||||
#line 36 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 35 "sqljson.pgc"
|
||||
#line 36 "sqljson.pgc"
|
||||
|
||||
printf("Found json=%s\n", json);
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select json_object ( 1 : 1 , '2' : null absent on null without unique returning jsonb )", ECPGt_EOIT,
|
||||
ECPGt_char,(json),(long)1024,(long)1,(1024)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
||||
#line 38 "sqljson.pgc"
|
||||
#line 39 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 38 "sqljson.pgc"
|
||||
#line 39 "sqljson.pgc"
|
||||
|
||||
printf("Found json=%s\n", json);
|
||||
|
||||
{ ECPGdisconnect(__LINE__, "CURRENT");
|
||||
#line 41 "sqljson.pgc"
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "with val ( js ) as ( values ( '{ \"a\": 1, \"b\": [{ \"a\": 1, \"b\": 0, \"a\": 2 }] }' ) ) select js is json \"IS JSON\" , js is not json \"IS NOT JSON\" , js is json value \"IS VALUE\" , js is json object \"IS OBJECT\" , js is json array \"IS ARRAY\" , js is json scalar \"IS SCALAR\" , js is json without unique keys \"WITHOUT UNIQUE\" , js is json with unique keys \"WITH UNIQUE\" from val", ECPGt_EOIT,
|
||||
ECPGt_bool,&(is_json[0]),(long)1,(long)1,sizeof(bool),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_bool,&(is_json[1]),(long)1,(long)1,sizeof(bool),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_bool,&(is_json[2]),(long)1,(long)1,sizeof(bool),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_bool,&(is_json[3]),(long)1,(long)1,sizeof(bool),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_bool,&(is_json[4]),(long)1,(long)1,sizeof(bool),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_bool,&(is_json[5]),(long)1,(long)1,sizeof(bool),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_bool,&(is_json[6]),(long)1,(long)1,sizeof(bool),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_bool,&(is_json[7]),(long)1,(long)1,sizeof(bool),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
||||
#line 54 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 41 "sqljson.pgc"
|
||||
#line 54 "sqljson.pgc"
|
||||
|
||||
for (int i = 0; i < sizeof(is_json); i++)
|
||||
printf("Found is_json[%d]: %s\n", i, is_json[i] ? "true" : "false");
|
||||
|
||||
{ ECPGdisconnect(__LINE__, "CURRENT");
|
||||
#line 58 "sqljson.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 58 "sqljson.pgc"
|
||||
|
||||
|
||||
return 0;
|
||||
|
@ -2,68 +2,90 @@
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ECPGconnect: opening database ecpg1_regression on <DEFAULT> port <DEFAULT>
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ECPGsetcommit on line 18: action "on"; connection "ecpg1_regression"
|
||||
[NO_PID]: ECPGsetcommit on line 19: action "on"; connection "ecpg1_regression"
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 20: query: select json_object ( returning text ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: ecpg_execute on line 21: query: select json_object ( returning text ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 20: using PQexec
|
||||
[NO_PID]: ecpg_execute on line 21: using PQexec
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_process_output on line 20: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: ecpg_process_output on line 21: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 20: RESULT: {} offset: -1; array: no
|
||||
[NO_PID]: ecpg_get_data on line 21: RESULT: {} offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 23: query: select json_object ( returning text format json ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: ecpg_execute on line 24: query: select json_object ( returning text format json ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 23: using PQexec
|
||||
[NO_PID]: ecpg_execute on line 24: using PQexec
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_process_output on line 23: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: ecpg_process_output on line 24: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 23: RESULT: {} offset: -1; array: no
|
||||
[NO_PID]: ecpg_get_data on line 24: RESULT: {} offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 26: query: select json_array ( returning jsonb ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: ecpg_execute on line 27: query: select json_array ( returning jsonb ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 26: using PQexec
|
||||
[NO_PID]: ecpg_execute on line 27: using PQexec
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_process_output on line 26: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: ecpg_process_output on line 27: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_is_type_an_array on line 26: type (3802); C (1); array (no)
|
||||
[NO_PID]: ecpg_is_type_an_array on line 27: type (3802); C (1); array (no)
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 26: RESULT: [] offset: -1; array: no
|
||||
[NO_PID]: ecpg_get_data on line 27: RESULT: [] offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 29: query: select json_array ( returning jsonb format json ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: ecpg_execute on line 30: query: select json_array ( returning jsonb format json ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 29: using PQexec
|
||||
[NO_PID]: ecpg_execute on line 30: using PQexec
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_process_output on line 29: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: ecpg_process_output on line 30: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 29: RESULT: [] offset: -1; array: no
|
||||
[NO_PID]: ecpg_get_data on line 30: RESULT: [] offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 32: query: select json_object ( 1 : 1 , '1' : null with unique ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: ecpg_execute on line 33: query: select json_object ( 1 : 1 , '1' : null with unique ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 32: using PQexec
|
||||
[NO_PID]: ecpg_execute on line 33: using PQexec
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_check_PQresult on line 32: bad response - ERROR: duplicate JSON key "1"
|
||||
[NO_PID]: ecpg_check_PQresult on line 33: bad response - ERROR: duplicate JSON key "1"
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: raising sqlstate 22030 (sqlcode -400): duplicate JSON key "1" on line 32
|
||||
[NO_PID]: raising sqlstate 22030 (sqlcode -400): duplicate JSON key "1" on line 33
|
||||
[NO_PID]: sqlca: code: -400, state: 22030
|
||||
SQL error: duplicate JSON key "1" on line 32
|
||||
[NO_PID]: ecpg_execute on line 35: query: select json_object ( 1 : 1 , '2' : null , 1 : '2' absent on null without unique keys ); with 0 parameter(s) on connection ecpg1_regression
|
||||
SQL error: duplicate JSON key "1" on line 33
|
||||
[NO_PID]: ecpg_execute on line 36: query: select json_object ( 1 : 1 , '2' : null , 1 : '2' absent on null without unique keys ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 35: using PQexec
|
||||
[NO_PID]: ecpg_execute on line 36: using PQexec
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_process_output on line 35: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: ecpg_process_output on line 36: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_is_type_an_array on line 35: type (114); C (1); array (no)
|
||||
[NO_PID]: ecpg_is_type_an_array on line 36: type (114); C (1); array (no)
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 35: RESULT: {"1" : 1, "1" : "2"} offset: -1; array: no
|
||||
[NO_PID]: ecpg_get_data on line 36: RESULT: {"1" : 1, "1" : "2"} offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 38: query: select json_object ( 1 : 1 , '2' : null absent on null without unique returning jsonb ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: ecpg_execute on line 39: query: select json_object ( 1 : 1 , '2' : null absent on null without unique returning jsonb ); with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 38: using PQexec
|
||||
[NO_PID]: ecpg_execute on line 39: using PQexec
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_process_output on line 38: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: ecpg_process_output on line 39: correctly got 1 tuples with 1 fields
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 38: RESULT: {"1": 1} offset: -1; array: no
|
||||
[NO_PID]: ecpg_get_data on line 39: RESULT: {"1": 1} offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 42: query: with val ( js ) as ( values ( '{ "a": 1, "b": [{ "a": 1, "b": 0, "a": 2 }] }' ) ) select js is json "IS JSON" , js is not json "IS NOT JSON" , js is json value "IS VALUE" , js is json object "IS OBJECT" , js is json array "IS ARRAY" , js is json scalar "IS SCALAR" , js is json without unique keys "WITHOUT UNIQUE" , js is json with unique keys "WITH UNIQUE" from val; with 0 parameter(s) on connection ecpg1_regression
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_execute on line 42: using PQexec
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_process_output on line 42: correctly got 1 tuples with 8 fields
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 42: RESULT: t offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 42: RESULT: f offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 42: RESULT: t offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 42: RESULT: t offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 42: RESULT: f offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 42: RESULT: f offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 42: RESULT: t offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_get_data on line 42: RESULT: f offset: -1; array: no
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
[NO_PID]: ecpg_finish: connection ecpg1_regression closed
|
||||
[NO_PID]: sqlca: code: 0, state: 00000
|
||||
|
@ -4,3 +4,11 @@ Found json=[]
|
||||
Found json=[]
|
||||
Found json={"1" : 1, "1" : "2"}
|
||||
Found json={"1": 1}
|
||||
Found is_json[0]: true
|
||||
Found is_json[1]: false
|
||||
Found is_json[2]: true
|
||||
Found is_json[3]: true
|
||||
Found is_json[4]: false
|
||||
Found is_json[5]: false
|
||||
Found is_json[6]: true
|
||||
Found is_json[7]: false
|
||||
|
@ -10,6 +10,7 @@ main ()
|
||||
{
|
||||
EXEC SQL BEGIN DECLARE SECTION;
|
||||
char json[1024];
|
||||
bool is_json[8];
|
||||
EXEC SQL END DECLARE SECTION;
|
||||
|
||||
ECPGdebug (1, stderr);
|
||||
@ -38,6 +39,22 @@ EXEC SQL END DECLARE SECTION;
|
||||
EXEC SQL SELECT JSON_OBJECT(1: 1, '2': NULL ABSENT ON NULL WITHOUT UNIQUE RETURNING jsonb) INTO :json;
|
||||
printf("Found json=%s\n", json);
|
||||
|
||||
EXEC SQL WITH val (js) AS (VALUES ('{ "a": 1, "b": [{ "a": 1, "b": 0, "a": 2 }] }'))
|
||||
SELECT
|
||||
js IS JSON "IS JSON",
|
||||
js IS NOT JSON "IS NOT JSON",
|
||||
js IS JSON VALUE "IS VALUE",
|
||||
js IS JSON OBJECT "IS OBJECT",
|
||||
js IS JSON ARRAY "IS ARRAY",
|
||||
js IS JSON SCALAR "IS SCALAR",
|
||||
js IS JSON WITHOUT UNIQUE KEYS "WITHOUT UNIQUE",
|
||||
js IS JSON WITH UNIQUE KEYS "WITH UNIQUE"
|
||||
INTO :is_json[0], :is_json[1], :is_json[2], :is_json[3], :is_json[4],
|
||||
:is_json[5], :is_json[6], :is_json[7]
|
||||
FROM val;
|
||||
for (int i = 0; i < sizeof(is_json); i++)
|
||||
printf("Found is_json[%d]: %s\n", i, is_json[i] ? "true" : "false");
|
||||
|
||||
EXEC SQL DISCONNECT;
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user