mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Add test for view referencing labels shared by vertex and edge tables
Add a test for view containing labels which are shared by both vertex and edge tables. When such a label is dropped from only vertex tables or only edge tables, the view may be rendered invalid because it does not find any elements associated with the label. Right now, you get an error at run time. It would be correct per SQL standard to make this a syntax error (parse time error), which would require some restrict/cascade action when dropping labels. This is not a big problem, because you still get a clean error, but it might be worth improving sometime. Add a test case to record the current behavior. Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CAExHW5toFV8b984ipuBSAar-W50K%3D%2BXmPOcG5ZUZNP4jrf4zSg%40mail.gmail.com
This commit is contained in:
@@ -1012,6 +1012,25 @@ SELECT pg_get_viewdef('customers_us'::regclass);
|
||||
ORDER BY g.customer_name, g.product_name;
|
||||
(1 row)
|
||||
|
||||
-- l1 is shared by all vertex tables and edge tables. Dropping it
|
||||
-- only from all vertex tables renders a view unusable. It would
|
||||
-- probably be more correct that the DROP LABEL operations enforce
|
||||
-- RESTRICT or CASCADE.
|
||||
CREATE VIEW v_shared_label AS SELECT * FROM GRAPH_TABLE (g1 MATCH (v IS l1) COLUMNS (v.elname));
|
||||
BEGIN;
|
||||
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v1 DROP LABEL l1;
|
||||
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v2 DROP LABEL l1;
|
||||
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v3 DROP LABEL l1;
|
||||
SELECT * FROM v_shared_label;
|
||||
ERROR: no property graph element of type "vertex" has label "l1" associated with it in property graph "g1"
|
||||
ROLLBACK;
|
||||
SELECT pg_get_viewdef('v_shared_label'::regclass);
|
||||
pg_get_viewdef
|
||||
------------------------------------------------------------------------
|
||||
SELECT elname +
|
||||
FROM GRAPH_TABLE (g1 MATCH (v IS l1) COLUMNS (v.elname AS elname));
|
||||
(1 row)
|
||||
|
||||
-- test view/graph nesting
|
||||
CREATE VIEW customers_view AS SELECT customer_id, 'redacted' || customer_id AS name_redacted, address FROM customers;
|
||||
SELECT * FROM customers;
|
||||
|
||||
@@ -564,6 +564,19 @@ ALTER PROPERTY GRAPH myshop ALTER VERTEX TABLE products
|
||||
-- ruleutils reverse parsing
|
||||
SELECT pg_get_viewdef('customers_us'::regclass);
|
||||
|
||||
-- l1 is shared by all vertex tables and edge tables. Dropping it
|
||||
-- only from all vertex tables renders a view unusable. It would
|
||||
-- probably be more correct that the DROP LABEL operations enforce
|
||||
-- RESTRICT or CASCADE.
|
||||
CREATE VIEW v_shared_label AS SELECT * FROM GRAPH_TABLE (g1 MATCH (v IS l1) COLUMNS (v.elname));
|
||||
BEGIN;
|
||||
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v1 DROP LABEL l1;
|
||||
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v2 DROP LABEL l1;
|
||||
ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v3 DROP LABEL l1;
|
||||
SELECT * FROM v_shared_label;
|
||||
ROLLBACK;
|
||||
SELECT pg_get_viewdef('v_shared_label'::regclass);
|
||||
|
||||
-- test view/graph nesting
|
||||
|
||||
CREATE VIEW customers_view AS SELECT customer_id, 'redacted' || customer_id AS name_redacted, address FROM customers;
|
||||
|
||||
Reference in New Issue
Block a user