From: Peter Eisentraut Date: Wed, 28 Dec 2016 17:00:00 +0000 (-0500) Subject: Allow dropping multiple functions at once X-Git-Tag: REL_10_BETA1~770 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=583f6c414895e72c710f723fbb3649df664530d7;p=postgresql Allow dropping multiple functions at once The generic drop support already supported dropping multiple objects of the same kind at once. But the previous representation of function signatures across two grammar symbols and structure members made this cumbersome to do for functions, so it was not supported. Now that function signatures are represented by a single structure, it's trivial to add this support. Same for aggregates and operators. Reviewed-by: Jim Nasby Reviewed-by: Michael Paquier --- diff --git a/doc/src/sgml/ref/drop_aggregate.sgml b/doc/src/sgml/ref/drop_aggregate.sgml index c27c5eadf9..631b578df7 100644 --- a/doc/src/sgml/ref/drop_aggregate.sgml +++ b/doc/src/sgml/ref/drop_aggregate.sgml @@ -21,7 +21,7 @@ PostgreSQL documentation -DROP AGGREGATE [ IF EXISTS ] name ( aggregate_signature ) [ CASCADE | RESTRICT ] +DROP AGGREGATE [ IF EXISTS ] name ( aggregate_signature ) [, ...] [ CASCADE | RESTRICT ] where aggregate_signature is: @@ -155,7 +155,14 @@ DROP AGGREGATE myavg(integer); DROP AGGREGATE myrank(VARIADIC "any" ORDER BY VARIADIC "any"); - + + + To remove multiple aggregate functions in one command: + +DROP AGGREGATE myavg(integer), myavg(bigint); + + + Compatibility diff --git a/doc/src/sgml/ref/drop_function.sgml b/doc/src/sgml/ref/drop_function.sgml index 5883d13811..5969b084b4 100644 --- a/doc/src/sgml/ref/drop_function.sgml +++ b/doc/src/sgml/ref/drop_function.sgml @@ -21,7 +21,7 @@ PostgreSQL documentation -DROP FUNCTION [ IF EXISTS ] name ( [ [ argmode ] [ argname ] argtype [, ...] ] ) +DROP FUNCTION [ IF EXISTS ] name ( [ [ argmode ] [ argname ] argtype [, ...] ] ) [, ...] [ CASCADE | RESTRICT ] @@ -134,6 +134,12 @@ DROP FUNCTION [ IF EXISTS ] name ( DROP FUNCTION sqrt(integer); + + + + Drop multiple functions in one command: + +DROP FUNCTION sqrt(integer), sqrt(bigint); diff --git a/doc/src/sgml/ref/drop_operator.sgml b/doc/src/sgml/ref/drop_operator.sgml index 13dd974f38..fc82c3e0e3 100644 --- a/doc/src/sgml/ref/drop_operator.sgml +++ b/doc/src/sgml/ref/drop_operator.sgml @@ -21,7 +21,7 @@ PostgreSQL documentation -DROP OPERATOR [ IF EXISTS ] name ( { left_type | NONE } , { right_type | NONE } ) [ CASCADE | RESTRICT ] +DROP OPERATOR [ IF EXISTS ] name ( { left_type | NONE } , { right_type | NONE } ) [, ...] [ CASCADE | RESTRICT ] @@ -125,6 +125,12 @@ DROP OPERATOR ~ (none, bit); for type bigint: DROP OPERATOR ! (bigint, none); + + + + Remove multiple operators in one command: + +DROP OPERATOR ~ (none, bit), ! (bigint, none); diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 1b06d358b5..542b09b4b0 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -358,7 +358,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); %type privileges privilege_list %type privilege_target %type function_with_argtypes aggregate_with_argtypes operator_with_argtypes -%type function_with_argtypes_list +%type function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list %type defacl_privilege_target %type DefACLOption %type DefACLOptionList @@ -7495,6 +7495,12 @@ aggregate_with_argtypes: } ; +aggregate_with_argtypes_list: + aggregate_with_argtypes { $$ = list_make1($1); } + | aggregate_with_argtypes_list ',' aggregate_with_argtypes + { $$ = lappend($1, $3); } + ; + createfunc_opt_list: /* Must be at least one to prevent conflict */ createfunc_opt_item { $$ = list_make1($1); } @@ -7676,21 +7682,21 @@ opt_restrict: *****************************************************************************/ RemoveFuncStmt: - DROP FUNCTION function_with_argtypes opt_drop_behavior + DROP FUNCTION function_with_argtypes_list opt_drop_behavior { DropStmt *n = makeNode(DropStmt); n->removeType = OBJECT_FUNCTION; - n->objects = list_make1($3); + n->objects = $3; n->behavior = $4; n->missing_ok = false; n->concurrent = false; $$ = (Node *)n; } - | DROP FUNCTION IF_P EXISTS function_with_argtypes opt_drop_behavior + | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior { DropStmt *n = makeNode(DropStmt); n->removeType = OBJECT_FUNCTION; - n->objects = list_make1($5); + n->objects = $5; n->behavior = $6; n->missing_ok = true; n->concurrent = false; @@ -7699,21 +7705,21 @@ RemoveFuncStmt: ; RemoveAggrStmt: - DROP AGGREGATE aggregate_with_argtypes opt_drop_behavior + DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior { DropStmt *n = makeNode(DropStmt); n->removeType = OBJECT_AGGREGATE; - n->objects = list_make1($3); + n->objects = $3; n->behavior = $4; n->missing_ok = false; n->concurrent = false; $$ = (Node *)n; } - | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes opt_drop_behavior + | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior { DropStmt *n = makeNode(DropStmt); n->removeType = OBJECT_AGGREGATE; - n->objects = list_make1($5); + n->objects = $5; n->behavior = $6; n->missing_ok = true; n->concurrent = false; @@ -7722,21 +7728,21 @@ RemoveAggrStmt: ; RemoveOperStmt: - DROP OPERATOR operator_with_argtypes opt_drop_behavior + DROP OPERATOR operator_with_argtypes_list opt_drop_behavior { DropStmt *n = makeNode(DropStmt); n->removeType = OBJECT_OPERATOR; - n->objects = list_make1($3); + n->objects = $3; n->behavior = $4; n->missing_ok = false; n->concurrent = false; $$ = (Node *)n; } - | DROP OPERATOR IF_P EXISTS operator_with_argtypes opt_drop_behavior + | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior { DropStmt *n = makeNode(DropStmt); n->removeType = OBJECT_OPERATOR; - n->objects = list_make1($5); + n->objects = $5; n->behavior = $6; n->missing_ok = true; n->concurrent = false; @@ -7768,6 +7774,12 @@ any_operator: { $$ = lcons(makeString($1), $3); } ; +operator_with_argtypes_list: + operator_with_argtypes { $$ = list_make1($1); } + | operator_with_argtypes_list ',' operator_with_argtypes + { $$ = lappend($1, $3); } + ; + operator_with_argtypes: any_operator oper_argtypes { diff --git a/src/test/regress/expected/create_function_3.out b/src/test/regress/expected/create_function_3.out index 7bb957b51b..cc4e98a1d4 100644 --- a/src/test/regress/expected/create_function_3.out +++ b/src/test/regress/expected/create_function_3.out @@ -217,9 +217,10 @@ SELECT routine_name, ordinal_position, parameter_name, parameter_default functest_is_3 | 2 | b | (7 rows) +DROP FUNCTION functest_IS_1(int, int, text), functest_IS_2(int), functest_IS_3(int); -- Cleanups DROP SCHEMA temp_func_test CASCADE; -NOTICE: drop cascades to 19 other objects +NOTICE: drop cascades to 16 other objects DETAIL: drop cascades to function functest_a_1(text,date) drop cascades to function functest_a_2(text[]) drop cascades to function functest_a_3() @@ -236,8 +237,5 @@ drop cascades to function functext_f_1(integer) drop cascades to function functext_f_2(integer) drop cascades to function functext_f_3(integer) drop cascades to function functext_f_4(integer) -drop cascades to function functest_is_1(integer,integer,text) -drop cascades to function functest_is_2(integer) -drop cascades to function functest_is_3(integer) DROP USER regress_unpriv_user; RESET search_path; diff --git a/src/test/regress/sql/create_function_3.sql b/src/test/regress/sql/create_function_3.sql index 43454ef2f7..66a463b089 100644 --- a/src/test/regress/sql/create_function_3.sql +++ b/src/test/regress/sql/create_function_3.sql @@ -156,6 +156,8 @@ SELECT routine_name, ordinal_position, parameter_name, parameter_default WHERE routine_schema = 'temp_func_test' AND routine_name ~ '^functest_is_' ORDER BY 1, 2; +DROP FUNCTION functest_IS_1(int, int, text), functest_IS_2(int), functest_IS_3(int); + -- Cleanups DROP SCHEMA temp_func_test CASCADE;