Skip to content

Commit d127828

Browse files
committed
Change PROCEDURE to FUNCTION in CREATE OPERATOR syntax
Since procedures are now a different thing from functions, change the CREATE OPERATOR syntax to use FUNCTION in the clause that specifies the function. PROCEDURE is still accepted for compatibility. Reported-by: Peter Geoghegan <pg@bowt.ie> Reviewed-by: Jonathan S. Katz <jonathan.katz@excoventures.com>
1 parent b194957 commit d127828

File tree

7 files changed

+30
-18
lines changed

7 files changed

+30
-18
lines changed

doc/src/sgml/extend.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ CREATE TYPE pair AS ( k text, v text );
10151015
CREATE OR REPLACE FUNCTION pair(text, text)
10161016
RETURNS pair LANGUAGE SQL AS 'SELECT ROW($1, $2)::@extschema@.pair;';
10171017

1018-
CREATE OPERATOR ~> (LEFTARG = text, RIGHTARG = text, PROCEDURE = pair);
1018+
CREATE OPERATOR ~> (LEFTARG = text, RIGHTARG = text, FUNCTION = pair);
10191019

10201020
-- "SET search_path" is easy to get right, but qualified names perform better.
10211021
CREATE OR REPLACE FUNCTION lower(pair)

doc/src/sgml/ref/create_operator.sgml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PostgreSQL documentation
2222
<refsynopsisdiv>
2323
<synopsis>
2424
CREATE OPERATOR <replaceable>name</replaceable> (
25-
PROCEDURE = <replaceable class="parameter">function_name</replaceable>
25+
{FUNCTION|PROCEDURE} = <replaceable class="parameter">function_name</replaceable>
2626
[, LEFTARG = <replaceable class="parameter">left_type</replaceable> ] [, RIGHTARG = <replaceable class="parameter">right_type</replaceable> ]
2727
[, COMMUTATOR = <replaceable class="parameter">com_op</replaceable> ] [, NEGATOR = <replaceable class="parameter">neg_op</replaceable> ]
2828
[, RESTRICT = <replaceable class="parameter">res_proc</replaceable> ] [, JOIN = <replaceable class="parameter">join_proc</replaceable> ]
@@ -99,6 +99,14 @@ CREATE OPERATOR <replaceable>name</replaceable> (
9999
of arguments (either one or two) of the indicated types.
100100
</para>
101101

102+
<para>
103+
In the syntax of <literal>CREATE OPERATOR</literal>, the keywords
104+
<literal>FUNCTION</literal> and <literal>PROCEDURE</literal> are
105+
equivalent, but the referenced function must in any case be a function, not
106+
a procedure. The use of the keyword <literal>PROCEDURE</literal> here is
107+
historical and deprecated.
108+
</para>
109+
102110
<para>
103111
The other clauses specify optional operator optimization clauses.
104112
Their meaning is detailed in <xref linkend="xoper-optimization"/>.
@@ -264,7 +272,7 @@ COMMUTATOR = OPERATOR(myschema.===) ,
264272
CREATE OPERATOR === (
265273
LEFTARG = box,
266274
RIGHTARG = box,
267-
PROCEDURE = area_equal_function,
275+
FUNCTION = area_equal_function,
268276
COMMUTATOR = ===,
269277
NEGATOR = !==,
270278
RESTRICT = area_restriction_function,

doc/src/sgml/xoper.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CREATE FUNCTION complex_add(complex, complex)
4444
CREATE OPERATOR + (
4545
leftarg = complex,
4646
rightarg = complex,
47-
procedure = complex_add,
47+
function = complex_add,
4848
commutator = +
4949
);
5050
</programlisting>
@@ -66,7 +66,7 @@ SELECT (a + b) AS c FROM test_complex;
6666
<para>
6767
We've shown how to create a binary operator here. To create unary
6868
operators, just omit one of <literal>leftarg</literal> (for left unary) or
69-
<literal>rightarg</literal> (for right unary). The <literal>procedure</literal>
69+
<literal>rightarg</literal> (for right unary). The <literal>function</literal>
7070
clause and the argument clauses are the only required items in
7171
<command>CREATE OPERATOR</command>. The <literal>commutator</literal>
7272
clause shown in the example is an optional hint to the query

src/backend/commands/operatorcmds.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* NOTES
2222
* These things must be defined and committed in the following order:
2323
* "create function":
24-
* input/output, recv/send procedures
24+
* input/output, recv/send functions
2525
* "create type":
2626
* type
2727
* "create operator":
@@ -79,8 +79,8 @@ DefineOperator(List *names, List *parameters)
7979
Oid rettype;
8080
List *commutatorName = NIL; /* optional commutator operator name */
8181
List *negatorName = NIL; /* optional negator operator name */
82-
List *restrictionName = NIL; /* optional restrict. sel. procedure */
83-
List *joinName = NIL; /* optional join sel. procedure */
82+
List *restrictionName = NIL; /* optional restrict. sel. function */
83+
List *joinName = NIL; /* optional join sel. function */
8484
Oid functionOid; /* functions converted to OID */
8585
Oid restrictionOid;
8686
Oid joinOid;
@@ -120,6 +120,9 @@ DefineOperator(List *names, List *parameters)
120120
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
121121
errmsg("SETOF type not allowed for operator argument")));
122122
}
123+
/* "function" and "procedure" are equivalent here */
124+
else if (strcmp(defel->defname, "function") == 0)
125+
functionName = defGetQualifiedName(defel);
123126
else if (strcmp(defel->defname, "procedure") == 0)
124127
functionName = defGetQualifiedName(defel);
125128
else if (strcmp(defel->defname, "commutator") == 0)
@@ -159,7 +162,7 @@ DefineOperator(List *names, List *parameters)
159162
if (functionName == NIL)
160163
ereport(ERROR,
161164
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
162-
errmsg("operator procedure must be specified")));
165+
errmsg("operator function must be specified")));
163166

164167
/* Transform type names to type OIDs */
165168
if (typeName1)
@@ -245,8 +248,8 @@ DefineOperator(List *names, List *parameters)
245248
functionOid, /* function for operator */
246249
commutatorName, /* optional commutator operator name */
247250
negatorName, /* optional negator operator name */
248-
restrictionOid, /* optional restrict. sel. procedure */
249-
joinOid, /* optional join sel. procedure name */
251+
restrictionOid, /* optional restrict. sel. function */
252+
joinOid, /* optional join sel. function name */
250253
canMerge, /* operator merges */
251254
canHash); /* operator hashes */
252255
}
@@ -393,10 +396,10 @@ AlterOperator(AlterOperatorStmt *stmt)
393396
Datum values[Natts_pg_operator];
394397
bool nulls[Natts_pg_operator];
395398
bool replaces[Natts_pg_operator];
396-
List *restrictionName = NIL; /* optional restrict. sel. procedure */
399+
List *restrictionName = NIL; /* optional restrict. sel. function */
397400
bool updateRestriction = false;
398401
Oid restrictionOid;
399-
List *joinName = NIL; /* optional join sel. procedure */
402+
List *joinName = NIL; /* optional join sel. function */
400403
bool updateJoin = false;
401404
Oid joinOid;
402405

@@ -436,6 +439,7 @@ AlterOperator(AlterOperatorStmt *stmt)
436439
*/
437440
else if (strcmp(defel->defname, "leftarg") == 0 ||
438441
strcmp(defel->defname, "rightarg") == 0 ||
442+
strcmp(defel->defname, "function") == 0 ||
439443
strcmp(defel->defname, "procedure") == 0 ||
440444
strcmp(defel->defname, "commutator") == 0 ||
441445
strcmp(defel->defname, "negator") == 0 ||

src/bin/pg_dump/pg_dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12415,7 +12415,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
1241512415
oprregproc = convertRegProcReference(fout, oprcode);
1241612416
if (oprregproc)
1241712417
{
12418-
appendPQExpBuffer(details, " PROCEDURE = %s", oprregproc);
12418+
appendPQExpBuffer(details, " FUNCTION = %s", oprregproc);
1241912419
free(oprregproc);
1242012420
}
1242112421

src/test/regress/expected/create_operator.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
CREATE OPERATOR ## (
55
leftarg = path,
66
rightarg = path,
7-
procedure = path_inter,
7+
function = path_inter,
88
commutator = ##
99
);
1010
CREATE OPERATOR <% (
@@ -107,7 +107,7 @@ ERROR: at least one of leftarg or rightarg must be specified
107107
CREATE OPERATOR #@%# (
108108
leftarg = int8
109109
);
110-
ERROR: operator procedure must be specified
110+
ERROR: operator function must be specified
111111
-- Should fail. CREATE OPERATOR requires USAGE on TYPE
112112
BEGIN TRANSACTION;
113113
CREATE ROLE regress_rol_op3;
@@ -202,4 +202,4 @@ WARNING: operator attribute "Restrict" not recognized
202202
WARNING: operator attribute "Join" not recognized
203203
WARNING: operator attribute "Hashes" not recognized
204204
WARNING: operator attribute "Merges" not recognized
205-
ERROR: operator procedure must be specified
205+
ERROR: operator function must be specified

src/test/regress/sql/create_operator.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
CREATE OPERATOR ## (
66
leftarg = path,
77
rightarg = path,
8-
procedure = path_inter,
8+
function = path_inter,
99
commutator = ##
1010
);
1111

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy