You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by jg...@apache.org on 2021/06/18 01:20:06 UTC

[incubator-age] branch master updated: Altered Error When Trying to Create Existing Graph

This is an automated email from the ASF dual-hosted git repository.

jgemignani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-age.git


The following commit(s) were added to refs/heads/master by this push:
     new f7519c9  Altered Error When Trying to Create Existing Graph
f7519c9 is described below

commit f7519c9661c23ecd283ef82495f8b8f7b6244280
Author: John Gemignani <jr...@gmail.com>
AuthorDate: Thu Jun 17 18:11:45 2021 -0700

    Altered Error When Trying to Create Existing Graph
    
    Modified error message when using existing graph name for new graph.
    Now it checks before starting the create graph process if a graph with
    the current name already exists or not. If the a graph with input name
    already exists it quits the graph creation process with an error.
    
    This resolves issue #66 on Github.
    
    Added regression tests for this case as well.
---
 .gitignore                            | 4 ++++
 regress/expected/scan.out             | 2 ++
 regress/sql/scan.sql                  | 2 ++
 src/backend/commands/graph_commands.c | 9 +++++++++
 4 files changed, 17 insertions(+)

diff --git a/.gitignore b/.gitignore
index 9d22eb4..98bce84 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,6 @@
 *.o
 *.so
+.gitignore
+build.sh
+.idea
+.deps
diff --git a/regress/expected/scan.out b/regress/expected/scan.out
index 90276d4..f40cba8 100644
--- a/regress/expected/scan.out
+++ b/regress/expected/scan.out
@@ -25,6 +25,8 @@ NOTICE:  graph "scan" has been created
  
 (1 row)
 
+SELECT create_graph('scan');
+ERROR:  graph "scan" already exists
 --
 -- multi-line comment
 --
diff --git a/regress/sql/scan.sql b/regress/sql/scan.sql
index 3fedaa0..97804e5 100644
--- a/regress/sql/scan.sql
+++ b/regress/sql/scan.sql
@@ -22,6 +22,8 @@ SET search_path TO ag_catalog;
 
 SELECT create_graph('scan');
 
+SELECT create_graph('scan');
+
 --
 -- multi-line comment
 --
diff --git a/src/backend/commands/graph_commands.c b/src/backend/commands/graph_commands.c
index c201ee8..c298324 100644
--- a/src/backend/commands/graph_commands.c
+++ b/src/backend/commands/graph_commands.c
@@ -61,6 +61,7 @@ Datum create_graph(PG_FUNCTION_ARGS)
 {
     char *graph;
     Name graph_name;
+    char *graph_name_str;
     Oid nsp_id;
 
     if (PG_ARGISNULL(0))
@@ -70,6 +71,14 @@ Datum create_graph(PG_FUNCTION_ARGS)
     }
     graph_name = PG_GETARG_NAME(0);
 
+    graph_name_str = NameStr(*graph_name);
+    if (graph_exists(graph_name_str))
+    {
+        ereport(ERROR,
+                (errcode(ERRCODE_UNDEFINED_SCHEMA),
+                        errmsg("graph \"%s\" already exists", graph_name_str)));
+    }
+
     nsp_id = create_schema_for_graph(graph_name);
 
     insert_graph(graph_name, nsp_id);