Skip to content

Commit

Permalink
add pgbench test for RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Feb 22, 2023
1 parent 2190124 commit cc9cfe2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/pgbench/1652/new.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
WITH pgrst_source AS (
SELECT "get_projects_below".*
FROM (
SELECT '[{"id": 4}]'::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 _("id" integer) LIMIT 1
) pgrst_args,
LATERAL "test"."get_projects_below"("id" := pgrst_args.id)
)
SELECT
null::bigint AS total_result_set,
pg_catalog.count(_postgrest_t) AS page_total,
coalesce(json_agg(_postgrest_t), '[]')::character varying AS body,
nullif(current_setting('response.headers', true), '') AS response_headers,
nullif(current_setting('response.status', true), '') AS response_status
FROM (SELECT "projects".* FROM "pgrst_source" AS "projects") _postgrest_t;
15 changes: 15 additions & 0 deletions test/pgbench/1652/old.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
WITH pgrst_source AS (
WITH
pgrst_payload AS (SELECT '{"id": 4}'::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),
pgrst_args AS ( SELECT * FROM json_to_recordset((SELECT val FROM pgrst_body)) AS _("id" integer) )
SELECT "get_projects_below".*
FROM "test"."get_projects_below"("id" := (SELECT "id" FROM pgrst_args LIMIT 1))
)
SELECT
null::bigint AS total_result_set,
pg_catalog.count(_postgrest_t) AS page_total,
coalesce(json_agg(_postgrest_t), '[]')::character varying AS body,
nullif(current_setting('response.headers', true), '') AS response_headers,
nullif(current_setting('response.status', true), '') AS response_status
FROM (SELECT "projects".* FROM "pgrst_source" AS "projects") _postgrest_t;
3 changes: 3 additions & 0 deletions test/pgbench/fixtures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ ALTER TABLE test.complex_items

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

-- For testing #1652
-- ALTER FUNCTION test.get_projects_below ( integer) STABLE;

0 comments on commit cc9cfe2

Please sign in to comment.