Skip to content

Commit

Permalink
add pgbench test
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Feb 22, 2023
1 parent 5fb8ef0 commit 2190124
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/pgbench/2677/new.sql
Original file line number Diff line number Diff line change
@@ -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}]'::json as json_data
) pgrst_payload,
LATERAL (
SELECT CASE WHEN json_typeof(pgrst_payload.json_data) = 'array' THEN pgrst_payload.json_data ELSE json_build_array(pgrst_payload.json_data) END AS val
) pgrst_uniform_json,
LATERAL (
SELECT * FROM json_to_recordset (pgrst_uniform_json.val) AS _ ("arr_data" integer[], "field-with_sep" integer, "id" bigint, "name" text)
) pgrst_body
RETURNING "test"."complex_items".*
7 changes: 7 additions & 0 deletions test/pgbench/2677/old.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
WITH
pgrst_payload AS (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}]'::json AS json_data),
pgrst_body AS ( SELECT CASE WHEN json_typeof(json_data) = 'array' THEN json_data ELSE json_build_array(json_data) END AS val FROM pgrst_payload)
INSERT INTO "test"."complex_items"("arr_data", "field-with_sep", "id", "name")
SELECT "arr_data", "field-with_sep", "id", "name"
FROM json_to_recordset ((SELECT val FROM pgrst_body)) AS _ ("arr_data" integer[], "field-with_sep" integer, "id" bigint, "name" text)
RETURNING "test"."complex_items".*
8 changes: 8 additions & 0 deletions test/pgbench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## pgbench tests

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
```
7 changes: 7 additions & 0 deletions test/pgbench/fixtures.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\ir ../spec/fixtures/load.sql

ALTER TABLE test.complex_items
DROP CONSTRAINT complex_items_pkey;

ALTER TABLE test.complex_items
ALTER COLUMN "field-with_sep" DROP NOT NULL;

0 comments on commit 2190124

Please sign in to comment.