diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 13:44:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 13:44:03 +0000 |
commit | 293913568e6a7a86fd1479e1cff8e2ecb58d6568 (patch) | |
tree | fc3b469a3ec5ab71b36ea97cc7aaddb838423a0c /src/interfaces/ecpg/test/sql/sqljson.pgc | |
parent | Initial commit. (diff) | |
download | postgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.tar.xz postgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.zip |
Adding upstream version 16.2.upstream/16.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/interfaces/ecpg/test/sql/sqljson.pgc')
-rw-r--r-- | src/interfaces/ecpg/test/sql/sqljson.pgc | 61 |
1 files changed, 61 insertions, 0 deletions
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 <stdio.h> + +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; +} |