From c76c15be501a2a7fe639753c1077e907b9802fc4 Mon Sep 17 00:00:00 2001 From: gurkanindibay Date: Sun, 17 Dec 2023 21:09:45 +0300 Subject: [PATCH] Handles null comment cases --- .../deparser/deparse_database_stmts.c | 5 ++- .../distributed/deparser/deparse_role_stmts.c | 6 ++-- .../regress/expected/comment_on_database.out | 32 ++++++++++++++----- src/test/regress/expected/comment_on_role.out | 16 ++++++++++ src/test/regress/sql/comment_on_database.sql | 11 +++++++ src/test/regress/sql/comment_on_role.sql | 11 +++++++ 6 files changed, 66 insertions(+), 15 deletions(-) diff --git a/src/backend/distributed/deparser/deparse_database_stmts.c b/src/backend/distributed/deparser/deparse_database_stmts.c index 6744de9ef41..924b26b890e 100644 --- a/src/backend/distributed/deparser/deparse_database_stmts.c +++ b/src/backend/distributed/deparser/deparse_database_stmts.c @@ -323,10 +323,9 @@ DeparseDatabaseCommentStmt(Node *node) char *databaseName = strVal(stmt->object); + char *comment = stmt->comment!=NULL?quote_literal_cstr(stmt->comment):"NULL"; - appendStringInfo(&str, "COMMENT ON DATABASE %s IS %s;", - databaseName, - quote_literal_cstr(stmt->comment)); + appendStringInfo(&str, "COMMENT ON DATABASE %s IS %s;",databaseName,comment); return str.data; } diff --git a/src/backend/distributed/deparser/deparse_role_stmts.c b/src/backend/distributed/deparser/deparse_role_stmts.c index ff877ee8ba1..d2295db4411 100644 --- a/src/backend/distributed/deparser/deparse_role_stmts.c +++ b/src/backend/distributed/deparser/deparse_role_stmts.c @@ -543,11 +543,9 @@ DeparseRoleCommentStmt(Node *node) initStringInfo(&str); char *roleName = strVal(stmt->object); + char *comment = stmt->comment!=NULL?quote_literal_cstr(stmt->comment):"NULL"; - - appendStringInfo(&str, "COMMENT ON ROLE %s IS %s;", - roleName, - quote_literal_cstr(stmt->comment)); + appendStringInfo(&str, "COMMENT ON ROLE %s IS %s;",roleName,comment); return str.data; } diff --git a/src/test/regress/expected/comment_on_database.out b/src/test/regress/expected/comment_on_database.out index 840216513b5..0bf0e43ad33 100644 --- a/src/test/regress/expected/comment_on_database.out +++ b/src/test/regress/expected/comment_on_database.out @@ -5,10 +5,10 @@ create database test1; comment on DATABASE test1 is 'test-comment'; SELECT result FROM run_command_on_all_nodes( $$ - SELECT ds.description AS database_comment -FROM pg_database d -LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid -WHERE d.datname = 'test1'; + SELECT ds.description AS database_comment + FROM pg_database d + LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid + WHERE d.datname = 'test1'; $$ ); result @@ -21,10 +21,10 @@ WHERE d.datname = 'test1'; comment on DATABASE test1 is 'comment-needs\!escape'; SELECT result FROM run_command_on_all_nodes( $$ - SELECT ds.description AS database_comment -FROM pg_database d -LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid -WHERE d.datname = 'test1'; + SELECT ds.description AS database_comment + FROM pg_database d + LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid + WHERE d.datname = 'test1'; $$ ); result @@ -32,6 +32,22 @@ WHERE d.datname = 'test1'; comment-needs\!escape comment-needs\!escape comment-needs\!escape +(3 rows) + +comment on DATABASE test1 is null; +SELECT result FROM run_command_on_all_nodes( + $$ + SELECT ds.description AS database_comment + FROM pg_database d + LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid + WHERE d.datname = 'test1'; + $$ +); + result +--------------------------------------------------------------------- + + + (3 rows) drop DATABASE test1; diff --git a/src/test/regress/expected/comment_on_role.out b/src/test/regress/expected/comment_on_role.out index dad4f4533b7..62f308c9050 100644 --- a/src/test/regress/expected/comment_on_role.out +++ b/src/test/regress/expected/comment_on_role.out @@ -31,6 +31,22 @@ SELECT result FROM run_command_on_all_nodes( comment-needs\!escape comment-needs\!escape comment-needs\!escape +(3 rows) + +comment on role role1 is NULL; +SELECT result FROM run_command_on_all_nodes( + $$ + SELECT ds.description AS role_comment + FROM pg_roles r + LEFT JOIN pg_shdescription ds ON r.oid = ds.objoid + WHERE r.rolname = 'role1'; + $$ +); + result +--------------------------------------------------------------------- + + + (3 rows) drop role role1; diff --git a/src/test/regress/sql/comment_on_database.sql b/src/test/regress/sql/comment_on_database.sql index e7429c22114..e51fb34482b 100644 --- a/src/test/regress/sql/comment_on_database.sql +++ b/src/test/regress/sql/comment_on_database.sql @@ -27,6 +27,17 @@ SELECT result FROM run_command_on_all_nodes( $$ ); +comment on DATABASE test1 is null; + +SELECT result FROM run_command_on_all_nodes( + $$ + SELECT ds.description AS database_comment + FROM pg_database d + LEFT JOIN pg_shdescription ds ON d.oid = ds.objoid + WHERE d.datname = 'test1'; + $$ +); + drop DATABASE test1; reset citus.enable_create_database_propagation; reset citus.grep_remote_commands; diff --git a/src/test/regress/sql/comment_on_role.sql b/src/test/regress/sql/comment_on_role.sql index 457c3af54fc..30e050aa08c 100644 --- a/src/test/regress/sql/comment_on_role.sql +++ b/src/test/regress/sql/comment_on_role.sql @@ -26,6 +26,17 @@ SELECT result FROM run_command_on_all_nodes( $$ ); +comment on role role1 is NULL; + +SELECT result FROM run_command_on_all_nodes( + $$ + SELECT ds.description AS role_comment + FROM pg_roles r + LEFT JOIN pg_shdescription ds ON r.oid = ds.objoid + WHERE r.rolname = 'role1'; + $$ +); + drop role role1; reset citus.grep_remote_commands; reset citus.log_remote_commands;