From 293913568e6a7a86fd1479e1cff8e2ecb58d6568 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 15:44:03 +0200 Subject: Adding upstream version 16.2. Signed-off-by: Daniel Baumann --- src/interfaces/ecpg/test/sql/sqljson.pgc | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/interfaces/ecpg/test/sql/sqljson.pgc (limited to 'src/interfaces/ecpg/test/sql/sqljson.pgc') diff --git a/src/interfaces/ecpg/test/sql/sqljson.pgc b/src/interfaces/ecpg/test/sql/sqljson.pgc new file mode 100644 index 0000000..a005503 --- /dev/null +++ b/src/interfaces/ecpg/test/sql/sqljson.pgc @@ -0,0 +1,61 @@ +#include + +EXEC SQL INCLUDE sqlca; +exec sql include ../regression; + +EXEC SQL WHENEVER SQLERROR sqlprint; + +int +main () +{ +EXEC SQL BEGIN DECLARE SECTION; + char json[1024]; + bool is_json[8]; +EXEC SQL END DECLARE SECTION; + + ECPGdebug (1, stderr); + + EXEC SQL CONNECT TO REGRESSDB1; + EXEC SQL SET AUTOCOMMIT = ON; + + EXEC SQL SELECT JSON_OBJECT(RETURNING text) INTO :json; + printf("Found json=%s\n", json); + + EXEC SQL SELECT JSON_OBJECT(RETURNING text FORMAT JSON) INTO :json; + printf("Found json=%s\n", json); + + EXEC SQL SELECT JSON_ARRAY(RETURNING jsonb) INTO :json; + printf("Found json=%s\n", json); + + EXEC SQL SELECT JSON_ARRAY(RETURNING jsonb FORMAT JSON) INTO :json; + printf("Found json=%s\n", json); + + EXEC SQL SELECT JSON_OBJECT(1: 1, '1': NULL WITH UNIQUE) INTO :json; + // error + + EXEC SQL SELECT JSON_OBJECT(1: 1, '2': NULL, 1: '2' ABSENT ON NULL WITHOUT UNIQUE KEYS) INTO :json; + printf("Found json=%s\n", json); + + 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; +} -- cgit v1.2.3