From d12782898eb5979bef3c6dd0d80b93d1aaf53cac Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 15 Aug 2018 18:05:46 +0200 Subject: 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 Reviewed-by: Jonathan S. Katz --- doc/src/sgml/extend.sgml | 2 +- doc/src/sgml/ref/create_operator.sgml | 12 ++++++++++-- doc/src/sgml/xoper.sgml | 4 ++-- src/backend/commands/operatorcmds.c | 20 ++++++++++++-------- src/bin/pg_dump/pg_dump.c | 2 +- src/test/regress/expected/create_operator.out | 6 +++--- src/test/regress/sql/create_operator.sql | 2 +- 7 files changed, 30 insertions(+), 18 deletions(-) diff --git a/doc/src/sgml/extend.sgml b/doc/src/sgml/extend.sgml index a3cb064131..d5731621e7 100644 --- a/doc/src/sgml/extend.sgml +++ b/doc/src/sgml/extend.sgml @@ -1015,7 +1015,7 @@ CREATE TYPE pair AS ( k text, v text ); CREATE OR REPLACE FUNCTION pair(text, text) RETURNS pair LANGUAGE SQL AS 'SELECT ROW($1, $2)::@extschema@.pair;'; -CREATE OPERATOR ~> (LEFTARG = text, RIGHTARG = text, PROCEDURE = pair); +CREATE OPERATOR ~> (LEFTARG = text, RIGHTARG = text, FUNCTION = pair); -- "SET search_path" is easy to get right, but qualified names perform better. CREATE OR REPLACE FUNCTION lower(pair) diff --git a/doc/src/sgml/ref/create_operator.sgml b/doc/src/sgml/ref/create_operator.sgml index c8263437ab..d5c385c087 100644 --- a/doc/src/sgml/ref/create_operator.sgml +++ b/doc/src/sgml/ref/create_operator.sgml @@ -22,7 +22,7 @@ PostgreSQL documentation CREATE OPERATOR name ( - PROCEDURE = function_name + {FUNCTION|PROCEDURE} = function_name [, LEFTARG = left_type ] [, RIGHTARG = right_type ] [, COMMUTATOR = com_op ] [, NEGATOR = neg_op ] [, RESTRICT = res_proc ] [, JOIN = join_proc ] @@ -99,6 +99,14 @@ CREATE OPERATOR name ( of arguments (either one or two) of the indicated types. + + In the syntax of CREATE OPERATOR, the keywords + FUNCTION and PROCEDURE are + equivalent, but the referenced function must in any case be a function, not + a procedure. The use of the keyword PROCEDURE here is + historical and deprecated. + + The other clauses specify optional operator optimization clauses. Their meaning is detailed in . @@ -264,7 +272,7 @@ COMMUTATOR = OPERATOR(myschema.===) , CREATE OPERATOR === ( LEFTARG = box, RIGHTARG = box, - PROCEDURE = area_equal_function, + FUNCTION = area_equal_function, COMMUTATOR = ===, NEGATOR = !==, RESTRICT = area_restriction_function, diff --git a/doc/src/sgml/xoper.sgml b/doc/src/sgml/xoper.sgml index 2aa7cf9b64..2f5560ac50 100644 --- a/doc/src/sgml/xoper.sgml +++ b/doc/src/sgml/xoper.sgml @@ -44,7 +44,7 @@ CREATE FUNCTION complex_add(complex, complex) CREATE OPERATOR + ( leftarg = complex, rightarg = complex, - procedure = complex_add, + function = complex_add, commutator = + ); @@ -66,7 +66,7 @@ SELECT (a + b) AS c FROM test_complex; We've shown how to create a binary operator here. To create unary operators, just omit one of leftarg (for left unary) or - rightarg (for right unary). The procedure + rightarg (for right unary). The function clause and the argument clauses are the only required items in CREATE OPERATOR. The commutator clause shown in the example is an optional hint to the query diff --git a/src/backend/commands/operatorcmds.c b/src/backend/commands/operatorcmds.c index f0da4c5279..8fd8f7e8cf 100644 --- a/src/backend/commands/operatorcmds.c +++ b/src/backend/commands/operatorcmds.c @@ -21,7 +21,7 @@ * NOTES * These things must be defined and committed in the following order: * "create function": - * input/output, recv/send procedures + * input/output, recv/send functions * "create type": * type * "create operator": @@ -79,8 +79,8 @@ DefineOperator(List *names, List *parameters) Oid rettype; List *commutatorName = NIL; /* optional commutator operator name */ List *negatorName = NIL; /* optional negator operator name */ - List *restrictionName = NIL; /* optional restrict. sel. procedure */ - List *joinName = NIL; /* optional join sel. procedure */ + List *restrictionName = NIL; /* optional restrict. sel. function */ + List *joinName = NIL; /* optional join sel. function */ Oid functionOid; /* functions converted to OID */ Oid restrictionOid; Oid joinOid; @@ -120,6 +120,9 @@ DefineOperator(List *names, List *parameters) (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("SETOF type not allowed for operator argument"))); } + /* "function" and "procedure" are equivalent here */ + else if (strcmp(defel->defname, "function") == 0) + functionName = defGetQualifiedName(defel); else if (strcmp(defel->defname, "procedure") == 0) functionName = defGetQualifiedName(defel); else if (strcmp(defel->defname, "commutator") == 0) @@ -159,7 +162,7 @@ DefineOperator(List *names, List *parameters) if (functionName == NIL) ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), - errmsg("operator procedure must be specified"))); + errmsg("operator function must be specified"))); /* Transform type names to type OIDs */ if (typeName1) @@ -245,8 +248,8 @@ DefineOperator(List *names, List *parameters) functionOid, /* function for operator */ commutatorName, /* optional commutator operator name */ negatorName, /* optional negator operator name */ - restrictionOid, /* optional restrict. sel. procedure */ - joinOid, /* optional join sel. procedure name */ + restrictionOid, /* optional restrict. sel. function */ + joinOid, /* optional join sel. function name */ canMerge, /* operator merges */ canHash); /* operator hashes */ } @@ -393,10 +396,10 @@ AlterOperator(AlterOperatorStmt *stmt) Datum values[Natts_pg_operator]; bool nulls[Natts_pg_operator]; bool replaces[Natts_pg_operator]; - List *restrictionName = NIL; /* optional restrict. sel. procedure */ + List *restrictionName = NIL; /* optional restrict. sel. function */ bool updateRestriction = false; Oid restrictionOid; - List *joinName = NIL; /* optional join sel. procedure */ + List *joinName = NIL; /* optional join sel. function */ bool updateJoin = false; Oid joinOid; @@ -436,6 +439,7 @@ AlterOperator(AlterOperatorStmt *stmt) */ else if (strcmp(defel->defname, "leftarg") == 0 || strcmp(defel->defname, "rightarg") == 0 || + strcmp(defel->defname, "function") == 0 || strcmp(defel->defname, "procedure") == 0 || strcmp(defel->defname, "commutator") == 0 || strcmp(defel->defname, "negator") == 0 || diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 89056207b9..cd325c0484 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12415,7 +12415,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) oprregproc = convertRegProcReference(fout, oprcode); if (oprregproc) { - appendPQExpBuffer(details, " PROCEDURE = %s", oprregproc); + appendPQExpBuffer(details, " FUNCTION = %s", oprregproc); free(oprregproc); } diff --git a/src/test/regress/expected/create_operator.out b/src/test/regress/expected/create_operator.out index fd8b37fff5..77237f4850 100644 --- a/src/test/regress/expected/create_operator.out +++ b/src/test/regress/expected/create_operator.out @@ -4,7 +4,7 @@ CREATE OPERATOR ## ( leftarg = path, rightarg = path, - procedure = path_inter, + function = path_inter, commutator = ## ); CREATE OPERATOR <% ( @@ -107,7 +107,7 @@ ERROR: at least one of leftarg or rightarg must be specified CREATE OPERATOR #@%# ( leftarg = int8 ); -ERROR: operator procedure must be specified +ERROR: operator function must be specified -- Should fail. CREATE OPERATOR requires USAGE on TYPE BEGIN TRANSACTION; CREATE ROLE regress_rol_op3; @@ -202,4 +202,4 @@ WARNING: operator attribute "Restrict" not recognized WARNING: operator attribute "Join" not recognized WARNING: operator attribute "Hashes" not recognized WARNING: operator attribute "Merges" not recognized -ERROR: operator procedure must be specified +ERROR: operator function must be specified diff --git a/src/test/regress/sql/create_operator.sql b/src/test/regress/sql/create_operator.sql index 9edf32b3f8..625e9b9748 100644 --- a/src/test/regress/sql/create_operator.sql +++ b/src/test/regress/sql/create_operator.sql @@ -5,7 +5,7 @@ CREATE OPERATOR ## ( leftarg = path, rightarg = path, - procedure = path_inter, + function = path_inter, commutator = ## ); -- cgit v1.2.1