Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76f412a

Browse files
committed
Remove factorial operators, leaving only the factorial() function.
The "!" operator is our only built-in postfix operator. Remove it,on the way to removal of grammar support for postfix operators.There is also a "!!" prefix operator, but since it's been markeddeprecated for most of its existence, we might as well remove it too.Also zap the SQL alias function numeric_fac(), which seems to haveequally little reason to live.Mark Dilger, based on work by myself and Robert Haas;review by John NaylorDiscussion:https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
1 parent74d4608 commit76f412a

File tree

10 files changed

+33
-93
lines changed

10 files changed

+33
-93
lines changed

‎contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,6 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft1 t1 WHERE c1 = -c1; -- Op
653653
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (("C 1" = (- "C 1")))
654654
(3 rows)
655655

656-
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft1 t1 WHERE 1 = c1!; -- OpExpr(r)
657-
QUERY PLAN
658-
----------------------------------------------------------------------------------------------------------
659-
Foreign Scan on public.ft1 t1
660-
Output: c1, c2, c3, c4, c5, c6, c7, c8
661-
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((1::numeric = ("C 1" !)))
662-
(3 rows)
663-
664656
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft1 t1 WHERE (c1 IS NOT NULL) IS DISTINCT FROM (c1 IS NOT NULL); -- DistinctExpr
665657
QUERY PLAN
666658
--------------------------------------------------------------------------------------------------------------------------------------------

‎contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft1 t1 WHERE c1 IS NULL; -- Nu
307307
EXPLAIN (VERBOSE, COSTS OFF)SELECT*FROM ft1 t1WHERE c1IS NOT NULL;-- NullTest
308308
EXPLAIN (VERBOSE, COSTS OFF)SELECT*FROM ft1 t1WHERE round(abs(c1),0)=1;-- FuncExpr
309309
EXPLAIN (VERBOSE, COSTS OFF)SELECT*FROM ft1 t1WHERE c1=-c1;-- OpExpr(l)
310-
EXPLAIN (VERBOSE, COSTS OFF)SELECT*FROM ft1 t1WHERE1= c1!;-- OpExpr(r)
311310
EXPLAIN (VERBOSE, COSTS OFF)SELECT*FROM ft1 t1WHERE (c1IS NOT NULL) IS DISTINCTFROM (c1IS NOT NULL);-- DistinctExpr
312311
EXPLAIN (VERBOSE, COSTS OFF)SELECT*FROM ft1 t1WHERE c1= ANY(ARRAY[c2,1, c1+0]);-- ScalarArrayOpExpr
313312
EXPLAIN (VERBOSE, COSTS OFF)SELECT*FROM ft1 t1WHERE c1= (ARRAY[c1,c2,3])[1];-- SubscriptingRef

‎doc/src/sgml/func.sgml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,36 +1048,6 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
10481048
</para></entry>
10491049
</row>
10501050

1051-
<row>
1052-
<entry role="func_table_entry"><para role="func_signature">
1053-
<type>bigint</type> <literal>!</literal>
1054-
<returnvalue>numeric</returnvalue>
1055-
</para>
1056-
<para>
1057-
Factorial
1058-
(deprecated, use <link linkend="function-factorial"><function>factorial()</function></link> instead)
1059-
</para>
1060-
<para>
1061-
<literal>5 !</literal>
1062-
<returnvalue>120</returnvalue>
1063-
</para></entry>
1064-
</row>
1065-
1066-
<row>
1067-
<entry role="func_table_entry"><para role="func_signature">
1068-
<literal>!!</literal> <type>bigint</type>
1069-
<returnvalue>numeric</returnvalue>
1070-
</para>
1071-
<para>
1072-
Factorial as a prefix operator
1073-
(deprecated, use <link linkend="function-factorial"><function>factorial()</function></link> instead)
1074-
</para>
1075-
<para>
1076-
<literal>!! 5</literal>
1077-
<returnvalue>120</returnvalue>
1078-
</para></entry>
1079-
</row>
1080-
10811051
<row>
10821052
<entry role="func_table_entry"><para role="func_signature">
10831053
<literal>@</literal> <replaceable>numeric_type</replaceable>

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
/* FIXME: bump this before pushing! */
57-
#defineCATALOG_VERSION_NO202009031
56+
#defineCATALOG_VERSION_NO202009171
5857

5958
#endif

‎src/include/catalog/pg_operator.dat

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,6 @@
218218
oprname => '>=', oprleft => 'xid8', oprright => 'xid8', oprresult => 'bool',
219219
oprcom => '<=(xid8,xid8)', oprnegate => '<(xid8,xid8)', oprcode => 'xid8ge',
220220
oprrest => 'scalargesel', oprjoin => 'scalargejoinsel' },
221-
{ oid => '388', descr => 'deprecated, use factorial() instead',
222-
oprname => '!', oprkind => 'r', oprleft => 'int8', oprright => '0',
223-
oprresult => 'numeric', oprcode => 'numeric_fac' },
224-
{ oid => '389', descr => 'deprecated, use factorial() instead',
225-
oprname => '!!', oprkind => 'l', oprleft => '0', oprright => 'int8',
226-
oprresult => 'numeric', oprcode => 'numeric_fac' },
227221
{ oid => '385', descr => 'equal',
228222
oprname => '=', oprcanhash => 't', oprleft => 'cid', oprright => 'cid',
229223
oprresult => 'bool', oprcom => '=(cid,cid)', oprcode => 'cideq',

‎src/include/catalog/pg_proc.dat

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,6 @@
327327
{ oid => '110', descr => 'I/O',
328328
proname => 'unknownout', prorettype => 'cstring', proargtypes => 'unknown',
329329
prosrc => 'unknownout' },
330-
{ oid => '111',
331-
descr => 'implementation of deprecated ! and !! factorial operators',
332-
proname => 'numeric_fac', prorettype => 'numeric', proargtypes => 'int8',
333-
prosrc => 'numeric_fac' },
334330

335331
{ oid => '115',
336332
proname => 'box_above_eq', prorettype => 'bool', proargtypes => 'box box',

‎src/test/regress/expected/create_operator.out

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ CREATE OPERATOR <% (
1616
);
1717
CREATE OPERATOR @#@ (
1818
rightarg = int8,-- left unary
19-
procedure =numeric_fac
19+
procedure =factorial
2020
);
2121
CREATE OPERATOR #@# (
2222
leftarg = int8,-- right unary
23-
procedure =numeric_fac
23+
procedure =factorial
2424
);
2525
CREATE OPERATOR #%# (
2626
leftarg = int8,-- right unary
27-
procedure =numeric_fac
27+
procedure =factorial
2828
);
2929
-- Test operator created above
3030
SELECT point '(1,2)' <% widget '(0,0,3)' AS t,
@@ -40,7 +40,7 @@ ERROR: operator does not exist: integer ######
4040
-- => is disallowed now
4141
CREATE OPERATOR => (
4242
leftarg = int8,-- right unary
43-
procedure =numeric_fac
43+
procedure =factorial
4444
);
4545
ERROR: syntax error at or near "=>"
4646
LINE 1: CREATE OPERATOR => (
@@ -50,7 +50,7 @@ LINE 1: CREATE OPERATOR => (
5050
-- this is legal because ! is not allowed in sql ops
5151
CREATE OPERATOR !=- (
5252
leftarg = int8,-- right unary
53-
procedure =numeric_fac
53+
procedure =factorial
5454
);
5555
SELECT 2 !=-;
5656
?column?
@@ -128,23 +128,23 @@ REVOKE USAGE ON SCHEMA schema_op1 FROM regress_rol_op1;
128128
SET ROLE regress_rol_op1;
129129
CREATE OPERATOR schema_op1.#*# (
130130
leftarg = int8,-- right unary
131-
procedure =numeric_fac
131+
procedure =factorial
132132
);
133133
ERROR: permission denied for schema schema_op1
134134
ROLLBACK;
135135
-- Should fail. SETOF type functions not allowed as argument (testing leftarg)
136136
BEGIN TRANSACTION;
137137
CREATE OPERATOR #*# (
138138
leftarg = SETOF int8,
139-
procedure =numeric_fac
139+
procedure =factorial
140140
);
141141
ERROR: SETOF type not allowed for operator argument
142142
ROLLBACK;
143143
-- Should fail. SETOF type functions not allowed as argument (testing rightarg)
144144
BEGIN TRANSACTION;
145145
CREATE OPERATOR #*# (
146146
rightarg = SETOF int8,
147-
procedure =numeric_fac
147+
procedure =factorial
148148
);
149149
ERROR: SETOF type not allowed for operator argument
150150
ROLLBACK;
@@ -168,13 +168,13 @@ ROLLBACK;
168168
-- Should fail. Invalid attribute
169169
CREATE OPERATOR #@%# (
170170
leftarg = int8,-- right unary
171-
procedure =numeric_fac,
171+
procedure =factorial,
172172
invalid_att = int8
173173
);
174174
WARNING: operator attribute "invalid_att" not recognized
175175
-- Should fail. At least leftarg or rightarg should be mandatorily specified
176176
CREATE OPERATOR #@%# (
177-
procedure =numeric_fac
177+
procedure =factorial
178178
);
179179
ERROR: at least one of leftarg or rightarg must be specified
180180
-- Should fail. Procedure should be mandatorily specified

‎src/test/regress/expected/numeric.out

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,16 +2972,10 @@ ERROR: value overflows numeric format
29722972
--
29732973
-- Tests for factorial
29742974
--
2975-
SELECT 4!;
2976-
?column?
2977-
----------
2978-
24
2979-
(1 row)
2980-
2981-
SELECT !!3;
2982-
?column?
2983-
----------
2984-
6
2975+
SELECT factorial(4);
2976+
factorial
2977+
-----------
2978+
24
29852979
(1 row)
29862980

29872981
SELECT factorial(15);
@@ -2990,16 +2984,14 @@ SELECT factorial(15);
29902984
1307674368000
29912985
(1 row)
29922986

2993-
SELECT 100000!;
2987+
SELECTfactorial(100000);
29942988
ERROR: value overflows numeric format
2995-
SELECT0!;
2996-
?column?
2997-
----------
2998-
1
2989+
SELECTfactorial(0);
2990+
factorial
2991+
-----------
2992+
1
29992993
(1 row)
30002994

3001-
SELECT -4!;
3002-
ERROR: factorial of a negative number is undefined
30032995
SELECT factorial(-4);
30042996
ERROR: factorial of a negative number is undefined
30052997
--

‎src/test/regress/sql/create_operator.sql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ CREATE OPERATOR <% (
1919

2020
CREATE OPERATOR @#@ (
2121
rightarg= int8,-- left unary
22-
procedure=numeric_fac
22+
procedure=factorial
2323
);
2424

2525
CREATE OPERATOR#@# (
2626
leftarg= int8,-- right unary
27-
procedure=numeric_fac
27+
procedure=factorial
2828
);
2929

3030
CREATE OPERATOR#%# (
3131
leftarg= int8,-- right unary
32-
procedure=numeric_fac
32+
procedure=factorial
3333
);
3434

3535
-- Test operator created above
@@ -42,7 +42,7 @@ COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
4242
-- => is disallowed now
4343
CREATE OPERATOR=> (
4444
leftarg= int8,-- right unary
45-
procedure=numeric_fac
45+
procedure=factorial
4646
);
4747

4848
-- lexing of <=, >=, <>, != has a number of edge cases
@@ -51,7 +51,7 @@ CREATE OPERATOR => (
5151
-- this is legal because ! is not allowed in sql ops
5252
CREATE OPERATOR!=- (
5353
leftarg= int8,-- right unary
54-
procedure=numeric_fac
54+
procedure=factorial
5555
);
5656
SELECT2!=-;
5757
-- make sure lexer returns != as <> even in edge cases
@@ -85,7 +85,7 @@ REVOKE USAGE ON SCHEMA schema_op1 FROM regress_rol_op1;
8585
SET ROLE regress_rol_op1;
8686
CREATEOPERATORschema_op1.#*# (
8787
leftarg= int8,-- right unary
88-
procedure=numeric_fac
88+
procedure=factorial
8989
);
9090
ROLLBACK;
9191

@@ -94,7 +94,7 @@ ROLLBACK;
9494
BEGIN TRANSACTION;
9595
CREATE OPERATOR#*# (
9696
leftarg= SETOF int8,
97-
procedure=numeric_fac
97+
procedure=factorial
9898
);
9999
ROLLBACK;
100100

@@ -103,7 +103,7 @@ ROLLBACK;
103103
BEGIN TRANSACTION;
104104
CREATE OPERATOR#*# (
105105
rightarg= SETOF int8,
106-
procedure=numeric_fac
106+
procedure=factorial
107107
);
108108
ROLLBACK;
109109

@@ -129,13 +129,13 @@ ROLLBACK;
129129
-- Should fail. Invalid attribute
130130
CREATE OPERATOR#@%# (
131131
leftarg= int8,-- right unary
132-
procedure=numeric_fac,
132+
procedure=factorial,
133133
invalid_att= int8
134134
);
135135

136136
-- Should fail. At least leftarg or rightarg should be mandatorily specified
137137
CREATE OPERATOR#@%# (
138-
procedure=numeric_fac
138+
procedure=factorial
139139
);
140140

141141
-- Should fail. Procedure should be mandatorily specified

‎src/test/regress/sql/numeric.sql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,10 @@ SELECT lcm(9999 * (10::numeric)^131068 + (10::numeric^131068 - 1), 2); -- overfl
13001300
--
13011301
-- Tests for factorial
13021302
--
1303-
SELECT4!;
1304-
SELECT !!3;
1303+
SELECT factorial(4);
13051304
SELECT factorial(15);
1306-
SELECT100000!;
1307-
SELECT0!;
1308-
SELECT-4!;
1305+
SELECT factorial(100000);
1306+
SELECT factorial(0);
13091307
SELECT factorial(-4);
13101308

13111309
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp