feat: undefined json keys as defaults w/ Prefer:undefined-keys
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
INSERT INTO "test"."complex_items"("arr_data", "field-with_sep", "id", "name")
|
||||
SELECT pgrst_body."arr_data", pgrst_body."field-with_sep", pgrst_body."id", pgrst_body."name"
|
||||
FROM (
|
||||
SELECT '[{"id": 4, "name": "Vier"}, {"id": 5, "name": "Funf", "arr_data": null}, {"id": 6, "name": "Sechs", "arr_data": [1, 2, 3], "field-with_sep": 6}]'::jsonb as json_data
|
||||
) pgrst_payload,
|
||||
LATERAL (
|
||||
SELECT CASE WHEN jsonb_typeof(pgrst_payload.json_data) = 'array' THEN pgrst_payload.json_data ELSE jsonb_build_array(pgrst_payload.json_data) END AS val
|
||||
) pgrst_uniform_json,
|
||||
LATERAL (
|
||||
SELECT jsonb_agg(jsonb_build_object('field-with_sep', 1) || elem) AS vals from jsonb_array_elements(pgrst_uniform_json.val) elem
|
||||
) pgrst_json_defs,
|
||||
LATERAL (
|
||||
SELECT * FROM jsonb_to_recordset (pgrst_json_defs.vals) AS _ ("arr_data" integer[], "field-with_sep" integer, "id" bigint, "name" text)
|
||||
) pgrst_body
|
||||
RETURNING "test"."complex_items".*;
|
||||
@@ -0,0 +1,12 @@
|
||||
INSERT INTO "test"."complex_items"("arr_data", "field-with_sep", "id", "name")
|
||||
SELECT pgrst_body."arr_data", pgrst_body."field-with_sep", pgrst_body."id", pgrst_body."name"
|
||||
FROM (
|
||||
SELECT '[{"id": 4, "name": "Vier"}, {"id": 5, "name": "Funf", "arr_data": null}, {"id": 6, "name": "Sechs", "arr_data": [1, 2, 3], "field-with_sep": 6}]'::jsonb as json_data
|
||||
) pgrst_payload,
|
||||
LATERAL (
|
||||
SELECT CASE WHEN jsonb_typeof(pgrst_payload.json_data) = 'array' THEN pgrst_payload.json_data ELSE jsonb_build_array(pgrst_payload.json_data) END AS val
|
||||
) pgrst_uniform_json,
|
||||
LATERAL (
|
||||
SELECT * FROM jsonb_to_recordset (pgrst_uniform_json.val) AS _ ("arr_data" integer[], "field-with_sep" integer, "id" bigint, "name" text)
|
||||
) pgrst_body
|
||||
RETURNING "test"."complex_items".*
|
||||
@@ -3,6 +3,11 @@
|
||||
Can be used as:
|
||||
|
||||
```
|
||||
postgrest-with-postgresql-15 -f test/pgbench/fixtures.sql pgbench -n -T 10 -f test/pgbench/2677/old.sql
|
||||
postgrest-with-postgresql-15 -f test/pgbench/fixtures.sql pgbench -n -T 10 -f test/pgbench/2677/new.sql
|
||||
postgrest-with-postgresql-15 -f test/pgbench/fixtures.sql pgbench -n -T 10 -f test/pgbench/1567/old.sql
|
||||
|
||||
postgrest-with-postgresql-15 -f test/pgbench/fixtures.sql pgbench -n -T 10 -f test/pgbench/1567/new.sql
|
||||
```
|
||||
|
||||
## Directory structure
|
||||
|
||||
The directory name is the issue number on github.
|
||||
|
||||
Reference in New Issue
Block a user