fix: Make recursive view parsing work with XMLTABLE + DEFAULT

This commit is contained in:
Wolfgang Walther
2021-12-24 19:01:20 +01:00
committed by Wolfgang Walther
parent ac3655df1d
commit b99c8c897c
4 changed files with 36 additions and 9 deletions
+1
View File
@@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #2020, Execute deferred constraint triggers when using `Prefer: tx=rollback` - @wolfgangwalther
- #2058, Return 204 No Content without Content-Type for PUT - @wolfgangwalther
- #2077, Fix `is` not working with upper or mixed case values like `NULL, TrUe, FaLsE` - @steve-chavez
- #2024, Fix schema cache loading when views with XMLTABLE and DEFAULT are present - @wolfgangwalther
## [9.0.0] - 2021-11-25
+8 -6
View File
@@ -792,7 +792,6 @@ pfkSourceColumns cols =
replace(
replace(
replace(
replace(
regexp_replace(
replace(
replace(
@@ -803,6 +802,7 @@ pfkSourceColumns cols =
replace(
replace(
replace(
replace(
replace(
view_definition::text,
-- This conversion to json is heavily optimized for performance.
@@ -814,9 +814,15 @@ pfkSourceColumns cols =
-- -----------------------------------------------
-- pattern | replacement | flags
-- -----------------------------------------------
-- `<>` in pg_node_tree is the same as `null` in JSON, but due to very poor performance of json_typeof
-- we need to make this an empty array here to prevent json_array_elements from throwing an error
-- when the targetList is null.
-- We'll need to put it first, to make the node protection below work for node lists that start with
-- null: `(<> ...`, too. This is the case for coldefexprs, when the first column does not have a default value.
'<>' , '()'
-- `,` is not part of the pg_node_tree format, but used in the regex.
-- This removes all `,` that might be part of column names.
',' , ''
), ',' , ''
-- The same applies for `{` and `}`, although those are used a lot in pg_node_tree.
-- We remove the escaped ones, which might be part of column names again.
), E'\\{' , ''
@@ -851,10 +857,6 @@ pfkSourceColumns cols =
), ')' , ']'
-- pg_node_tree has ` ` between list items, but JSON uses `,`
), ' ' , ','
-- `<>` in pg_node_tree is the same as `null` in JSON, but due to very poor performance of json_typeof
-- we need to make this an empty array here to prevent json_array_elements from throwing an error
-- when the targetList is null.
), '<>' , '[]'
)::json as view_definition
from views
),
+18
View File
@@ -2462,3 +2462,21 @@ BEGIN
INSERT INTO deferrable_unique_constraint VALUES (1), (1);
END$$;
-- This view is not used in any requests but just parsed by the pfkSourceColumns query.
-- XMLTABLE is only supported from PG 10 on
DO $do$
BEGIN
IF current_setting('server_version_num')::INT >= 100000 THEN
CREATE VIEW test.xml AS
SELECT *
FROM (SELECT ''::xml AS data) _,
XMLTABLE(
''
PASSING data
COLUMNS id int PATH '@id',
premier_name text PATH 'PREMIER_NAME' DEFAULT 'not specified'
);
END IF;
END
$do$;
+9 -3
View File
@@ -741,7 +741,9 @@ def test_admin_healthy_w_channel(defaultenv):
}
with run(env=env) as postgrest:
response = requests.get(f"http://localhost:{env['PGRST_ADMIN_SERVER_PORT']}/health")
response = requests.get(
f"http://localhost:{env['PGRST_ADMIN_SERVER_PORT']}/health"
)
assert response.status_code == 200
@@ -755,7 +757,9 @@ def test_admin_healthy_wo_channel(defaultenv):
}
with run(env=env) as postgrest:
response = requests.get(f"http://localhost:{env['PGRST_ADMIN_SERVER_PORT']}/health")
response = requests.get(
f"http://localhost:{env['PGRST_ADMIN_SERVER_PORT']}/health"
)
assert response.status_code == 200
@@ -768,5 +772,7 @@ def test_admin_not_found(defaultenv):
}
with run(env=env) as postgrest:
response = requests.get(f"http://localhost:{env['PGRST_ADMIN_SERVER_PORT']}/notfound")
response = requests.get(
f"http://localhost:{env['PGRST_ADMIN_SERVER_PORT']}/notfound"
)
assert response.status_code == 404