Skip to content

Commit 583f6c4

Browse files
committed
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 <Jim.Nasby@BlueTreble.com> Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
1 parent 2ca64c6 commit 583f6c4

File tree

6 files changed

+52
-21
lines changed

6 files changed

+52
-21
lines changed

doc/src/sgml/ref/drop_aggregate.sgml

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PostgreSQL documentation
2121

2222
<refsynopsisdiv>
2323
<synopsis>
24-
DROP AGGREGATE [ IF EXISTS ] <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) [ CASCADE | RESTRICT ]
24+
DROP AGGREGATE [ IF EXISTS ] <replaceable>name</replaceable> ( <replaceable>aggregate_signature</replaceable> ) [, ...] [ CASCADE | RESTRICT ]
2525

2626
<phrase>where <replaceable>aggregate_signature</replaceable> is:</phrase>
2727

@@ -155,7 +155,14 @@ DROP AGGREGATE myavg(integer);
155155
DROP AGGREGATE myrank(VARIADIC "any" ORDER BY VARIADIC "any");
156156
</programlisting>
157157
</para>
158-
</refsect1>
158+
159+
<para>
160+
To remove multiple aggregate functions in one command:
161+
<programlisting>
162+
DROP AGGREGATE myavg(integer), myavg(bigint);
163+
</programlisting>
164+
</para>
165+
</refsect1>
159166

160167
<refsect1>
161168
<title>Compatibility</title>

doc/src/sgml/ref/drop_function.sgml

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PostgreSQL documentation
2121

2222
<refsynopsisdiv>
2323
<synopsis>
24-
DROP FUNCTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
24+
DROP FUNCTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) [, ...]
2525
[ CASCADE | RESTRICT ]
2626
</synopsis>
2727
</refsynopsisdiv>
@@ -134,6 +134,12 @@ DROP FUNCTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable> (
134134

135135
<programlisting>
136136
DROP FUNCTION sqrt(integer);
137+
</programlisting></para>
138+
139+
<para>
140+
Drop multiple functions in one command:
141+
<programlisting>
142+
DROP FUNCTION sqrt(integer), sqrt(bigint);
137143
</programlisting></para>
138144
</refsect1>
139145

doc/src/sgml/ref/drop_operator.sgml

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PostgreSQL documentation
2121

2222
<refsynopsisdiv>
2323
<synopsis>
24-
DROP OPERATOR [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> ( { <replaceable class="PARAMETER">left_type</replaceable> | NONE } , { <replaceable class="PARAMETER">right_type</replaceable> | NONE } ) [ CASCADE | RESTRICT ]
24+
DROP OPERATOR [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> ( { <replaceable class="PARAMETER">left_type</replaceable> | NONE } , { <replaceable class="PARAMETER">right_type</replaceable> | NONE } ) [, ...] [ CASCADE | RESTRICT ]
2525
</synopsis>
2626
</refsynopsisdiv>
2727

@@ -125,6 +125,12 @@ DROP OPERATOR ~ (none, bit);
125125
for type <type>bigint</type>:
126126
<programlisting>
127127
DROP OPERATOR ! (bigint, none);
128+
</programlisting></para>
129+
130+
<para>
131+
Remove multiple operators in one command:
132+
<programlisting>
133+
DROP OPERATOR ~ (none, bit), ! (bigint, none);
128134
</programlisting></para>
129135
</refsect1>
130136

src/backend/parser/gram.y

+25-13
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
358358
%type <list> privileges privilege_list
359359
%type <privtarget> privilege_target
360360
%type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
361-
%type <list> function_with_argtypes_list
361+
%type <list> function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
362362
%type <ival> defacl_privilege_target
363363
%type <defelt> DefACLOption
364364
%type <list> DefACLOptionList
@@ -7495,6 +7495,12 @@ aggregate_with_argtypes:
74957495
}
74967496
;
74977497

7498+
aggregate_with_argtypes_list:
7499+
aggregate_with_argtypes { $$ = list_make1($1); }
7500+
| aggregate_with_argtypes_list ',' aggregate_with_argtypes
7501+
{ $$ = lappend($1, $3); }
7502+
;
7503+
74987504
createfunc_opt_list:
74997505
/* Must be at least one to prevent conflict */
75007506
createfunc_opt_item { $$ = list_make1($1); }
@@ -7676,21 +7682,21 @@ opt_restrict:
76767682
*****************************************************************************/
76777683

76787684
RemoveFuncStmt:
7679-
DROP FUNCTION function_with_argtypes opt_drop_behavior
7685+
DROP FUNCTION function_with_argtypes_list opt_drop_behavior
76807686
{
76817687
DropStmt *n = makeNode(DropStmt);
76827688
n->removeType = OBJECT_FUNCTION;
7683-
n->objects = list_make1($3);
7689+
n->objects = $3;
76847690
n->behavior = $4;
76857691
n->missing_ok = false;
76867692
n->concurrent = false;
76877693
$$ = (Node *)n;
76887694
}
7689-
| DROP FUNCTION IF_P EXISTS function_with_argtypes opt_drop_behavior
7695+
| DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
76907696
{
76917697
DropStmt *n = makeNode(DropStmt);
76927698
n->removeType = OBJECT_FUNCTION;
7693-
n->objects = list_make1($5);
7699+
n->objects = $5;
76947700
n->behavior = $6;
76957701
n->missing_ok = true;
76967702
n->concurrent = false;
@@ -7699,21 +7705,21 @@ RemoveFuncStmt:
76997705
;
77007706

77017707
RemoveAggrStmt:
7702-
DROP AGGREGATE aggregate_with_argtypes opt_drop_behavior
7708+
DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
77037709
{
77047710
DropStmt *n = makeNode(DropStmt);
77057711
n->removeType = OBJECT_AGGREGATE;
7706-
n->objects = list_make1($3);
7712+
n->objects = $3;
77077713
n->behavior = $4;
77087714
n->missing_ok = false;
77097715
n->concurrent = false;
77107716
$$ = (Node *)n;
77117717
}
7712-
| DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes opt_drop_behavior
7718+
| DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
77137719
{
77147720
DropStmt *n = makeNode(DropStmt);
77157721
n->removeType = OBJECT_AGGREGATE;
7716-
n->objects = list_make1($5);
7722+
n->objects = $5;
77177723
n->behavior = $6;
77187724
n->missing_ok = true;
77197725
n->concurrent = false;
@@ -7722,21 +7728,21 @@ RemoveAggrStmt:
77227728
;
77237729

77247730
RemoveOperStmt:
7725-
DROP OPERATOR operator_with_argtypes opt_drop_behavior
7731+
DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
77267732
{
77277733
DropStmt *n = makeNode(DropStmt);
77287734
n->removeType = OBJECT_OPERATOR;
7729-
n->objects = list_make1($3);
7735+
n->objects = $3;
77307736
n->behavior = $4;
77317737
n->missing_ok = false;
77327738
n->concurrent = false;
77337739
$$ = (Node *)n;
77347740
}
7735-
| DROP OPERATOR IF_P EXISTS operator_with_argtypes opt_drop_behavior
7741+
| DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
77367742
{
77377743
DropStmt *n = makeNode(DropStmt);
77387744
n->removeType = OBJECT_OPERATOR;
7739-
n->objects = list_make1($5);
7745+
n->objects = $5;
77407746
n->behavior = $6;
77417747
n->missing_ok = true;
77427748
n->concurrent = false;
@@ -7768,6 +7774,12 @@ any_operator:
77687774
{ $$ = lcons(makeString($1), $3); }
77697775
;
77707776

7777+
operator_with_argtypes_list:
7778+
operator_with_argtypes { $$ = list_make1($1); }
7779+
| operator_with_argtypes_list ',' operator_with_argtypes
7780+
{ $$ = lappend($1, $3); }
7781+
;
7782+
77717783
operator_with_argtypes:
77727784
any_operator oper_argtypes
77737785
{

src/test/regress/expected/create_function_3.out

+2-4
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ SELECT routine_name, ordinal_position, parameter_name, parameter_default
217217
functest_is_3 | 2 | b |
218218
(7 rows)
219219

220+
DROP FUNCTION functest_IS_1(int, int, text), functest_IS_2(int), functest_IS_3(int);
220221
-- Cleanups
221222
DROP SCHEMA temp_func_test CASCADE;
222-
NOTICE: drop cascades to 19 other objects
223+
NOTICE: drop cascades to 16 other objects
223224
DETAIL: drop cascades to function functest_a_1(text,date)
224225
drop cascades to function functest_a_2(text[])
225226
drop cascades to function functest_a_3()
@@ -236,8 +237,5 @@ drop cascades to function functext_f_1(integer)
236237
drop cascades to function functext_f_2(integer)
237238
drop cascades to function functext_f_3(integer)
238239
drop cascades to function functext_f_4(integer)
239-
drop cascades to function functest_is_1(integer,integer,text)
240-
drop cascades to function functest_is_2(integer)
241-
drop cascades to function functest_is_3(integer)
242240
DROP USER regress_unpriv_user;
243241
RESET search_path;

src/test/regress/sql/create_function_3.sql

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ SELECT routine_name, ordinal_position, parameter_name, parameter_default
156156
WHERE routine_schema = 'temp_func_test' AND routine_name ~ '^functest_is_'
157157
ORDER BY 1, 2;
158158

159+
DROP FUNCTION functest_IS_1(int, int, text), functest_IS_2(int), functest_IS_3(int);
160+
159161

160162
-- Cleanups
161163
DROP SCHEMA temp_func_test CASCADE;

0 commit comments

Comments
 (0)