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>
This commit is contained in:
parent
b7b16605db
commit
fd4417e8ac
doc/src/sgml
src
backend/commands
bin/pg_dump
test/regress
@ -1015,7 +1015,7 @@ CREATE TYPE pair AS ( k text, v text );
|
|||||||
CREATE OR REPLACE FUNCTION pair(text, text)
|
CREATE OR REPLACE FUNCTION pair(text, text)
|
||||||
RETURNS pair LANGUAGE SQL AS 'SELECT ROW($1, $2)::@extschema@.pair;';
|
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.
|
-- "SET search_path" is easy to get right, but qualified names perform better.
|
||||||
CREATE OR REPLACE FUNCTION lower(pair)
|
CREATE OR REPLACE FUNCTION lower(pair)
|
||||||
|
@ -22,7 +22,7 @@ PostgreSQL documentation
|
|||||||
<refsynopsisdiv>
|
<refsynopsisdiv>
|
||||||
<synopsis>
|
<synopsis>
|
||||||
CREATE OPERATOR <replaceable>name</replaceable> (
|
CREATE OPERATOR <replaceable>name</replaceable> (
|
||||||
PROCEDURE = <replaceable class="parameter">function_name</replaceable>
|
{FUNCTION|PROCEDURE} = <replaceable class="parameter">function_name</replaceable>
|
||||||
[, LEFTARG = <replaceable class="parameter">left_type</replaceable> ] [, RIGHTARG = <replaceable class="parameter">right_type</replaceable> ]
|
[, LEFTARG = <replaceable class="parameter">left_type</replaceable> ] [, RIGHTARG = <replaceable class="parameter">right_type</replaceable> ]
|
||||||
[, COMMUTATOR = <replaceable class="parameter">com_op</replaceable> ] [, NEGATOR = <replaceable class="parameter">neg_op</replaceable> ]
|
[, COMMUTATOR = <replaceable class="parameter">com_op</replaceable> ] [, NEGATOR = <replaceable class="parameter">neg_op</replaceable> ]
|
||||||
[, RESTRICT = <replaceable class="parameter">res_proc</replaceable> ] [, JOIN = <replaceable class="parameter">join_proc</replaceable> ]
|
[, RESTRICT = <replaceable class="parameter">res_proc</replaceable> ] [, JOIN = <replaceable class="parameter">join_proc</replaceable> ]
|
||||||
@ -99,6 +99,14 @@ CREATE OPERATOR <replaceable>name</replaceable> (
|
|||||||
of arguments (either one or two) of the indicated types.
|
of arguments (either one or two) of the indicated types.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
In the syntax of <literal>CREATE OPERATOR</literal>, the keywords
|
||||||
|
<literal>FUNCTION</literal> and <literal>PROCEDURE</literal> are
|
||||||
|
equivalent, but the referenced function must in any case be a function, not
|
||||||
|
a procedure. The use of the keyword <literal>PROCEDURE</literal> here is
|
||||||
|
historical and deprecated.
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The other clauses specify optional operator optimization clauses.
|
The other clauses specify optional operator optimization clauses.
|
||||||
Their meaning is detailed in <xref linkend="xoper-optimization"/>.
|
Their meaning is detailed in <xref linkend="xoper-optimization"/>.
|
||||||
@ -264,7 +272,7 @@ COMMUTATOR = OPERATOR(myschema.===) ,
|
|||||||
CREATE OPERATOR === (
|
CREATE OPERATOR === (
|
||||||
LEFTARG = box,
|
LEFTARG = box,
|
||||||
RIGHTARG = box,
|
RIGHTARG = box,
|
||||||
PROCEDURE = area_equal_function,
|
FUNCTION = area_equal_function,
|
||||||
COMMUTATOR = ===,
|
COMMUTATOR = ===,
|
||||||
NEGATOR = !==,
|
NEGATOR = !==,
|
||||||
RESTRICT = area_restriction_function,
|
RESTRICT = area_restriction_function,
|
||||||
|
@ -44,7 +44,7 @@ CREATE FUNCTION complex_add(complex, complex)
|
|||||||
CREATE OPERATOR + (
|
CREATE OPERATOR + (
|
||||||
leftarg = complex,
|
leftarg = complex,
|
||||||
rightarg = complex,
|
rightarg = complex,
|
||||||
procedure = complex_add,
|
function = complex_add,
|
||||||
commutator = +
|
commutator = +
|
||||||
);
|
);
|
||||||
</programlisting>
|
</programlisting>
|
||||||
@ -66,7 +66,7 @@ SELECT (a + b) AS c FROM test_complex;
|
|||||||
<para>
|
<para>
|
||||||
We've shown how to create a binary operator here. To create unary
|
We've shown how to create a binary operator here. To create unary
|
||||||
operators, just omit one of <literal>leftarg</literal> (for left unary) or
|
operators, just omit one of <literal>leftarg</literal> (for left unary) or
|
||||||
<literal>rightarg</literal> (for right unary). The <literal>procedure</literal>
|
<literal>rightarg</literal> (for right unary). The <literal>function</literal>
|
||||||
clause and the argument clauses are the only required items in
|
clause and the argument clauses are the only required items in
|
||||||
<command>CREATE OPERATOR</command>. The <literal>commutator</literal>
|
<command>CREATE OPERATOR</command>. The <literal>commutator</literal>
|
||||||
clause shown in the example is an optional hint to the query
|
clause shown in the example is an optional hint to the query
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
* NOTES
|
* NOTES
|
||||||
* These things must be defined and committed in the following order:
|
* These things must be defined and committed in the following order:
|
||||||
* "create function":
|
* "create function":
|
||||||
* input/output, recv/send procedures
|
* input/output, recv/send functions
|
||||||
* "create type":
|
* "create type":
|
||||||
* type
|
* type
|
||||||
* "create operator":
|
* "create operator":
|
||||||
@ -79,8 +79,8 @@ DefineOperator(List *names, List *parameters)
|
|||||||
Oid rettype;
|
Oid rettype;
|
||||||
List *commutatorName = NIL; /* optional commutator operator name */
|
List *commutatorName = NIL; /* optional commutator operator name */
|
||||||
List *negatorName = NIL; /* optional negator operator name */
|
List *negatorName = NIL; /* optional negator operator name */
|
||||||
List *restrictionName = NIL; /* optional restrict. sel. procedure */
|
List *restrictionName = NIL; /* optional restrict. sel. function */
|
||||||
List *joinName = NIL; /* optional join sel. procedure */
|
List *joinName = NIL; /* optional join sel. function */
|
||||||
Oid functionOid; /* functions converted to OID */
|
Oid functionOid; /* functions converted to OID */
|
||||||
Oid restrictionOid;
|
Oid restrictionOid;
|
||||||
Oid joinOid;
|
Oid joinOid;
|
||||||
@ -120,6 +120,9 @@ DefineOperator(List *names, List *parameters)
|
|||||||
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
||||||
errmsg("SETOF type not allowed for operator argument")));
|
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)
|
else if (strcmp(defel->defname, "procedure") == 0)
|
||||||
functionName = defGetQualifiedName(defel);
|
functionName = defGetQualifiedName(defel);
|
||||||
else if (strcmp(defel->defname, "commutator") == 0)
|
else if (strcmp(defel->defname, "commutator") == 0)
|
||||||
@ -159,7 +162,7 @@ DefineOperator(List *names, List *parameters)
|
|||||||
if (functionName == NIL)
|
if (functionName == NIL)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
||||||
errmsg("operator procedure must be specified")));
|
errmsg("operator function must be specified")));
|
||||||
|
|
||||||
/* Transform type names to type OIDs */
|
/* Transform type names to type OIDs */
|
||||||
if (typeName1)
|
if (typeName1)
|
||||||
@ -245,8 +248,8 @@ DefineOperator(List *names, List *parameters)
|
|||||||
functionOid, /* function for operator */
|
functionOid, /* function for operator */
|
||||||
commutatorName, /* optional commutator operator name */
|
commutatorName, /* optional commutator operator name */
|
||||||
negatorName, /* optional negator operator name */
|
negatorName, /* optional negator operator name */
|
||||||
restrictionOid, /* optional restrict. sel. procedure */
|
restrictionOid, /* optional restrict. sel. function */
|
||||||
joinOid, /* optional join sel. procedure name */
|
joinOid, /* optional join sel. function name */
|
||||||
canMerge, /* operator merges */
|
canMerge, /* operator merges */
|
||||||
canHash); /* operator hashes */
|
canHash); /* operator hashes */
|
||||||
}
|
}
|
||||||
@ -393,10 +396,10 @@ AlterOperator(AlterOperatorStmt *stmt)
|
|||||||
Datum values[Natts_pg_operator];
|
Datum values[Natts_pg_operator];
|
||||||
bool nulls[Natts_pg_operator];
|
bool nulls[Natts_pg_operator];
|
||||||
bool replaces[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;
|
bool updateRestriction = false;
|
||||||
Oid restrictionOid;
|
Oid restrictionOid;
|
||||||
List *joinName = NIL; /* optional join sel. procedure */
|
List *joinName = NIL; /* optional join sel. function */
|
||||||
bool updateJoin = false;
|
bool updateJoin = false;
|
||||||
Oid joinOid;
|
Oid joinOid;
|
||||||
|
|
||||||
@ -436,6 +439,7 @@ AlterOperator(AlterOperatorStmt *stmt)
|
|||||||
*/
|
*/
|
||||||
else if (strcmp(defel->defname, "leftarg") == 0 ||
|
else if (strcmp(defel->defname, "leftarg") == 0 ||
|
||||||
strcmp(defel->defname, "rightarg") == 0 ||
|
strcmp(defel->defname, "rightarg") == 0 ||
|
||||||
|
strcmp(defel->defname, "function") == 0 ||
|
||||||
strcmp(defel->defname, "procedure") == 0 ||
|
strcmp(defel->defname, "procedure") == 0 ||
|
||||||
strcmp(defel->defname, "commutator") == 0 ||
|
strcmp(defel->defname, "commutator") == 0 ||
|
||||||
strcmp(defel->defname, "negator") == 0 ||
|
strcmp(defel->defname, "negator") == 0 ||
|
||||||
|
@ -12406,7 +12406,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
|
|||||||
oprregproc = convertRegProcReference(fout, oprcode);
|
oprregproc = convertRegProcReference(fout, oprcode);
|
||||||
if (oprregproc)
|
if (oprregproc)
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(details, " PROCEDURE = %s", oprregproc);
|
appendPQExpBuffer(details, " FUNCTION = %s", oprregproc);
|
||||||
free(oprregproc);
|
free(oprregproc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
CREATE OPERATOR ## (
|
CREATE OPERATOR ## (
|
||||||
leftarg = path,
|
leftarg = path,
|
||||||
rightarg = path,
|
rightarg = path,
|
||||||
procedure = path_inter,
|
function = path_inter,
|
||||||
commutator = ##
|
commutator = ##
|
||||||
);
|
);
|
||||||
CREATE OPERATOR <% (
|
CREATE OPERATOR <% (
|
||||||
@ -107,7 +107,7 @@ ERROR: at least one of leftarg or rightarg must be specified
|
|||||||
CREATE OPERATOR #@%# (
|
CREATE OPERATOR #@%# (
|
||||||
leftarg = int8
|
leftarg = int8
|
||||||
);
|
);
|
||||||
ERROR: operator procedure must be specified
|
ERROR: operator function must be specified
|
||||||
-- Should fail. CREATE OPERATOR requires USAGE on TYPE
|
-- Should fail. CREATE OPERATOR requires USAGE on TYPE
|
||||||
BEGIN TRANSACTION;
|
BEGIN TRANSACTION;
|
||||||
CREATE ROLE regress_rol_op3;
|
CREATE ROLE regress_rol_op3;
|
||||||
@ -202,4 +202,4 @@ WARNING: operator attribute "Restrict" not recognized
|
|||||||
WARNING: operator attribute "Join" not recognized
|
WARNING: operator attribute "Join" not recognized
|
||||||
WARNING: operator attribute "Hashes" not recognized
|
WARNING: operator attribute "Hashes" not recognized
|
||||||
WARNING: operator attribute "Merges" not recognized
|
WARNING: operator attribute "Merges" not recognized
|
||||||
ERROR: operator procedure must be specified
|
ERROR: operator function must be specified
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
CREATE OPERATOR ## (
|
CREATE OPERATOR ## (
|
||||||
leftarg = path,
|
leftarg = path,
|
||||||
rightarg = path,
|
rightarg = path,
|
||||||
procedure = path_inter,
|
function = path_inter,
|
||||||
commutator = ##
|
commutator = ##
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user