Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 1305 - drop_label NULL cases #1306

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions regress/expected/drop.out
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,58 @@ SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname IN ('other_schema', 'd
other_schema
(1 row)

-- issue 1305
CREATE EXTENSION age;
LOAD 'age';
SET search_path TO ag_catalog;
SELECT create_graph('issue_1305');
NOTICE: graph "issue_1305" has been created
create_graph
--------------

(1 row)

SELECT create_vlabel('issue_1305', 'n');
NOTICE: VLabel "n" has been created
create_vlabel
---------------

(1 row)

SELECT create_elabel('issue_1305', 'r');
NOTICE: ELabel "r" has been created
create_elabel
---------------

(1 row)

SELECT drop_label('issue_1305', 'r', false);
NOTICE: label "issue_1305"."r" has been dropped
drop_label
------------

(1 row)

SELECT drop_label('issue_1305', 'r');
ERROR: rel_name not found for label "r"
SELECT drop_label('issue_1305', 'n', false);
NOTICE: label "issue_1305"."n" has been dropped
drop_label
------------

(1 row)

SELECT drop_label('issue_1305', 'n');
ERROR: rel_name not found for label "n"
SELECT * FROM drop_graph('issue_1305', true);
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table issue_1305._ag_label_vertex
drop cascades to table issue_1305._ag_label_edge
NOTICE: graph "issue_1305" has been dropped
drop_graph
------------

(1 row)

-- END
DROP EXTENSION age CASCADE;
16 changes: 16 additions & 0 deletions regress/sql/drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,19 @@ DROP EXTENSION age CASCADE;

-- 'other_schema' should exist, 'drop' should be deleted
SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname IN ('other_schema', 'drop');

-- issue 1305
CREATE EXTENSION age;
LOAD 'age';
SET search_path TO ag_catalog;
SELECT create_graph('issue_1305');
SELECT create_vlabel('issue_1305', 'n');
SELECT create_elabel('issue_1305', 'r');
SELECT drop_label('issue_1305', 'r', false);
SELECT drop_label('issue_1305', 'r');
SELECT drop_label('issue_1305', 'n', false);
SELECT drop_label('issue_1305', 'n');
SELECT * FROM drop_graph('issue_1305', true);

-- END
DROP EXTENSION age CASCADE;
19 changes: 19 additions & 0 deletions src/backend/commands/label_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,27 @@ Datum drop_label(PG_FUNCTION_ARGS)
errmsg("force option is not supported yet")));
}

/* validate schema_name */
schema_name = get_namespace_name(nsp_id);
if (schema_name == NULL)
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("schema_name not found for namespace id \"%d\"",
nsp_id)));
}

/* validate rel_name */
rel_name = get_rel_name(label_relation);
if (rel_name == NULL)
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_TABLE),
errmsg("rel_name not found for label \"%s\"",
label_name_str)));
}

/* build qualified name */
qname = list_make2(makeString(schema_name), makeString(rel_name));

remove_relation(qname);
Expand Down