From 951405125fb5428c9ddca6d873dc6adc9156778d Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 25 Feb 2026 10:06:33 +0100 Subject: [PATCH 07/10] Check for duplicate alias in ALTER PROPERTY GRAPH This would previously still fail with a unique index violation, but this gives a better error message. --- src/backend/commands/propgraphcmds.c | 18 ++++++++++++++++++ .../regress/expected/create_property_graph.out | 4 ++++ src/test/regress/sql/create_property_graph.sql | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/propgraphcmds.c b/src/backend/commands/propgraphcmds.c index deedb313c76..45d2ff1bbba 100644 --- a/src/backend/commands/propgraphcmds.c +++ b/src/backend/commands/propgraphcmds.c @@ -1341,6 +1341,15 @@ AlterPropGraph(ParseState *pstate, const AlterPropGraphStmt *stmt) table_close(rel, NoLock); + if (SearchSysCacheExists2(PROPGRAPHELALIAS, + ObjectIdGetDatum(pgrelid), + CStringGetDatum(vinfo->aliasname))) + ereport(ERROR, + errcode(ERRCODE_INVALID_OBJECT_DEFINITION), + errmsg("alias \"%s\" already exists in property graph \"%s\"", + vinfo->aliasname, stmt->pgname->relname), + parser_errposition(pstate, vertex->vtable->location)); + peoid = insert_element_record(pgaddress, vinfo); CommandCounterIncrement(); @@ -1401,6 +1410,15 @@ AlterPropGraph(ParseState *pstate, const AlterPropGraphStmt *stmt) table_close(rel, NoLock); + if (SearchSysCacheExists2(PROPGRAPHELALIAS, + ObjectIdGetDatum(pgrelid), + CStringGetDatum(einfo->aliasname))) + ereport(ERROR, + errcode(ERRCODE_INVALID_OBJECT_DEFINITION), + errmsg("alias \"%s\" already exists in property graph \"%s\"", + einfo->aliasname, stmt->pgname->relname), + parser_errposition(pstate, edge->etable->location)); + peoid = insert_element_record(pgaddress, einfo); CommandCounterIncrement(); diff --git a/src/test/regress/expected/create_property_graph.out b/src/test/regress/expected/create_property_graph.out index 95e34336f4e..ffc263cdb77 100644 --- a/src/test/regress/expected/create_property_graph.out +++ b/src/test/regress/expected/create_property_graph.out @@ -114,6 +114,10 @@ CREATE PROPERTY GRAPH gx VERTEX TABLES (t1 KEY (a), t2 KEY (i), t1 KEY (a)); ERROR: alias "t1" used more than once as element table LINE 1: ...Y GRAPH gx VERTEX TABLES (t1 KEY (a), t2 KEY (i), t1 KEY (a)... ^ +ALTER PROPERTY GRAPH g3 ADD VERTEX TABLES (t3 KEY (x)); -- duplicate alias +ERROR: alias "t3" already exists in property graph "g3" +LINE 1: ALTER PROPERTY GRAPH g3 ADD VERTEX TABLES (t3 KEY (x)); + ^ CREATE PROPERTY GRAPH gx VERTEX TABLES (t1 AS tt KEY (a), t2 KEY (i)) EDGE TABLES ( diff --git a/src/test/regress/sql/create_property_graph.sql b/src/test/regress/sql/create_property_graph.sql index a976905c5ee..5c2ced14753 100644 --- a/src/test/regress/sql/create_property_graph.sql +++ b/src/test/regress/sql/create_property_graph.sql @@ -94,6 +94,7 @@ CREATE PROPERTY GRAPH g5 CREATE UNLOGGED PROPERTY GRAPH gx VERTEX TABLES (xx, yy); CREATE PROPERTY GRAPH gx VERTEX TABLES (xx, yy); CREATE PROPERTY GRAPH gx VERTEX TABLES (t1 KEY (a), t2 KEY (i), t1 KEY (a)); +ALTER PROPERTY GRAPH g3 ADD VERTEX TABLES (t3 KEY (x)); -- duplicate alias CREATE PROPERTY GRAPH gx VERTEX TABLES (t1 AS tt KEY (a), t2 KEY (i)) EDGE TABLES ( @@ -168,7 +169,6 @@ CREATE PROPERTY GRAPH gx ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x, b AS zz); -- mismatching property names on label ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x); -- mismatching number of properties on label - ALTER PROPERTY GRAPH g1 OWNER TO regress_graph_user1; SET ROLE regress_graph_user1; GRANT SELECT ON PROPERTY GRAPH g1 TO regress_graph_user2; -- 2.53.0