mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Remove support for postfix (right-unary) operators.
This feature has been a thorn in our sides for a long time, causing many grammatical ambiguity problems. It doesn't seem worth the pain to continue to support it, so remove it. There are some follow-on improvements we can make in the grammar, but this commit only removes the bare minimum number of productions, plus assorted backend support code. Note that pg_dump and psql continue to have full support, since they may be used against older servers. However, pg_dump warns about postfix operators. There is also a check in pg_upgrade. Documentation-wise, I (tgl) largely removed the "left unary" terminology in favor of saying "prefix operator", which is a more standard and IMO less confusing term. I included a catversion bump, although no initial catalog data changes here, to mark the boundary at which oprkind = 'r' stopped being valid in pg_operator. Mark Dilger, based on work by myself and Robert Haas; review by John Naylor Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
This commit is contained in:
@ -5159,8 +5159,8 @@ SCRAM-SHA-256$<replaceable><iteration count></replaceable>:<replaceable>&l
|
||||
<structfield>oprkind</structfield> <type>char</type>
|
||||
</para>
|
||||
<para>
|
||||
<literal>b</literal> = infix (<quote>both</quote>), <literal>l</literal> = prefix
|
||||
(<quote>left</quote>), <literal>r</literal> = postfix (<quote>right</quote>)
|
||||
<literal>b</literal> = infix operator (<quote>both</quote>),
|
||||
or <literal>l</literal> = prefix operator (<quote>left</quote>)
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
@ -5188,7 +5188,7 @@ SCRAM-SHA-256$<replaceable><iteration count></replaceable>:<replaceable>&l
|
||||
(references <link linkend="catalog-pg-type"><structname>pg_type</structname></link>.<structfield>oid</structfield>)
|
||||
</para>
|
||||
<para>
|
||||
Type of the left operand
|
||||
Type of the left operand (0 if none)
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
@ -5266,7 +5266,7 @@ SCRAM-SHA-256$<replaceable><iteration count></replaceable>:<replaceable>&l
|
||||
</table>
|
||||
|
||||
<para>
|
||||
Unused column contain zeroes. For example, <structfield>oprleft</structfield>
|
||||
Unused columns contain zeroes. For example, <structfield>oprleft</structfield>
|
||||
is zero for a prefix operator.
|
||||
</para>
|
||||
|
||||
|
@ -251,7 +251,7 @@ ALTER EXTENSION <replaceable class="parameter">name</replaceable> DROP <replacea
|
||||
<para>
|
||||
The data type(s) of the operator's arguments (optionally
|
||||
schema-qualified). Write <literal>NONE</literal> for the missing argument
|
||||
of a prefix or postfix operator.
|
||||
of a prefix operator.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -21,13 +21,13 @@ PostgreSQL documentation
|
||||
|
||||
<refsynopsisdiv>
|
||||
<synopsis>
|
||||
ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , { <replaceable>right_type</replaceable> | NONE } )
|
||||
ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , <replaceable>right_type</replaceable> )
|
||||
OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
|
||||
|
||||
ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , { <replaceable>right_type</replaceable> | NONE } )
|
||||
ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , <replaceable>right_type</replaceable> )
|
||||
SET SCHEMA <replaceable>new_schema</replaceable>
|
||||
|
||||
ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , { <replaceable>right_type</replaceable> | NONE } )
|
||||
ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</replaceable> | NONE } , <replaceable>right_type</replaceable> )
|
||||
SET ( { RESTRICT = { <replaceable class="parameter">res_proc</replaceable> | NONE }
|
||||
| JOIN = { <replaceable class="parameter">join_proc</replaceable> | NONE }
|
||||
} [, ... ] )
|
||||
@ -79,8 +79,7 @@ ALTER OPERATOR <replaceable>name</replaceable> ( { <replaceable>left_type</repla
|
||||
<term><replaceable class="parameter">right_type</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The data type of the operator's right operand; write
|
||||
<literal>NONE</literal> if the operator has no right operand.
|
||||
The data type of the operator's right operand.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -141,7 +141,7 @@ ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="
|
||||
<para>
|
||||
In an <literal>OPERATOR</literal> clause,
|
||||
the operand data type(s) of the operator, or <literal>NONE</literal> to
|
||||
signify a left-unary or right-unary operator. Unlike the comparable
|
||||
signify a prefix operator. Unlike the comparable
|
||||
syntax in <command>CREATE OPERATOR CLASS</command>, the operand data types
|
||||
must always be specified.
|
||||
</para>
|
||||
|
@ -224,7 +224,7 @@ COMMENT ON
|
||||
<para>
|
||||
The data type(s) of the operator's arguments (optionally
|
||||
schema-qualified). Write <literal>NONE</literal> for the missing argument
|
||||
of a prefix or postfix operator.
|
||||
of a prefix operator.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -161,7 +161,7 @@ CREATE OPERATOR CLASS <replaceable class="parameter">name</replaceable> [ DEFAUL
|
||||
<para>
|
||||
In an <literal>OPERATOR</literal> clause,
|
||||
the operand data type(s) of the operator, or <literal>NONE</literal> to
|
||||
signify a left-unary or right-unary operator. The operand data
|
||||
signify a prefix operator. The operand data
|
||||
types can be omitted in the normal case where they are the same
|
||||
as the operator class's data type.
|
||||
</para>
|
||||
|
@ -86,20 +86,9 @@ CREATE OPERATOR <replaceable>name</replaceable> (
|
||||
</para>
|
||||
|
||||
<para>
|
||||
At least one of <literal>LEFTARG</literal> and <literal>RIGHTARG</literal> must be defined. For
|
||||
binary operators, both must be defined. For right unary
|
||||
operators, only <literal>LEFTARG</literal> should be defined, while for left
|
||||
unary operators only <literal>RIGHTARG</literal> should be defined.
|
||||
</para>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
Right unary, also called postfix, operators are deprecated and will be
|
||||
removed in <productname>PostgreSQL</productname> version 14.
|
||||
</para>
|
||||
</note>
|
||||
|
||||
<para>
|
||||
For binary operators, both <literal>LEFTARG</literal> and
|
||||
<literal>RIGHTARG</literal> must be defined. For prefix operators only
|
||||
<literal>RIGHTARG</literal> should be defined.
|
||||
The <replaceable class="parameter">function_name</replaceable>
|
||||
function must have been previously defined using <command>CREATE
|
||||
FUNCTION</command> and must be defined to accept the correct number
|
||||
@ -160,7 +149,7 @@ CREATE OPERATOR <replaceable>name</replaceable> (
|
||||
<listitem>
|
||||
<para>
|
||||
The data type of the operator's left operand, if any.
|
||||
This option would be omitted for a left-unary operator.
|
||||
This option would be omitted for a prefix operator.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@ -169,8 +158,7 @@ CREATE OPERATOR <replaceable>name</replaceable> (
|
||||
<term><replaceable class="parameter">right_type</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The data type of the operator's right operand, if any.
|
||||
This option would be omitted for a right-unary operator.
|
||||
The data type of the operator's right operand.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -21,7 +21,7 @@ PostgreSQL documentation
|
||||
|
||||
<refsynopsisdiv>
|
||||
<synopsis>
|
||||
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 ]
|
||||
DROP OPERATOR [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ( { <replaceable class="parameter">left_type</replaceable> | NONE } , <replaceable class="parameter">right_type</replaceable> ) [, ...] [ CASCADE | RESTRICT ]
|
||||
</synopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
@ -73,8 +73,7 @@ DROP OPERATOR [ IF EXISTS ] <replaceable class="parameter">name</replaceable> (
|
||||
<term><replaceable class="parameter">right_type</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The data type of the operator's right operand; write
|
||||
<literal>NONE</literal> if the operator has no right operand.
|
||||
The data type of the operator's right operand.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@ -113,24 +112,17 @@ DROP OPERATOR ^ (integer, integer);
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Remove the left unary bitwise complement operator
|
||||
Remove the bitwise-complement prefix operator
|
||||
<literal>~b</literal> for type <type>bit</type>:
|
||||
<programlisting>
|
||||
DROP OPERATOR ~ (none, bit);
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Remove the right unary factorial operator <literal>x!</literal>
|
||||
for type <type>bigint</type>:
|
||||
<programlisting>
|
||||
DROP OPERATOR ! (bigint, none);
|
||||
</programlisting></para>
|
||||
|
||||
<para>
|
||||
Remove multiple operators in one command:
|
||||
<programlisting>
|
||||
DROP OPERATOR ~ (none, bit), ! (bigint, none);
|
||||
DROP OPERATOR ~ (none, bit), ^ (integer, integer);
|
||||
</programlisting></para>
|
||||
</refsect1>
|
||||
|
||||
|
@ -836,7 +836,7 @@ CAST ( '<replaceable>string</replaceable>' AS <replaceable>type</replaceable> )
|
||||
<para>
|
||||
When working with non-SQL-standard operator names, you will usually
|
||||
need to separate adjacent operators with spaces to avoid ambiguity.
|
||||
For example, if you have defined a left unary operator named <literal>@</literal>,
|
||||
For example, if you have defined a prefix operator named <literal>@</literal>,
|
||||
you cannot write <literal>X*@Y</literal>; you must write
|
||||
<literal>X* @Y</literal> to ensure that
|
||||
<productname>PostgreSQL</productname> reads it as two operator names
|
||||
@ -1444,11 +1444,10 @@ $1.somecolumn
|
||||
</indexterm>
|
||||
|
||||
<para>
|
||||
There are three possible syntaxes for an operator invocation:
|
||||
There are two possible syntaxes for an operator invocation:
|
||||
<simplelist>
|
||||
<member><replaceable>expression</replaceable> <replaceable>operator</replaceable> <replaceable>expression</replaceable> (binary infix operator)</member>
|
||||
<member><replaceable>operator</replaceable> <replaceable>expression</replaceable> (unary prefix operator)</member>
|
||||
<member><replaceable>expression</replaceable> <replaceable>operator</replaceable> (unary postfix operator)</member>
|
||||
</simplelist>
|
||||
where the <replaceable>operator</replaceable> token follows the syntax
|
||||
rules of <xref linkend="sql-syntax-operators"/>, or is one of the
|
||||
|
@ -97,8 +97,8 @@ Operators
|
||||
<listitem>
|
||||
<para>
|
||||
<productname>PostgreSQL</productname> allows expressions with
|
||||
prefix and postfix unary (one-argument) operators,
|
||||
as well as binary (two-argument) operators. Like functions, operators can
|
||||
prefix (one-argument) operators,
|
||||
as well as infix (two-argument) operators. Like functions, operators can
|
||||
be overloaded, so the same problem of selecting the right operator
|
||||
exists.
|
||||
</para>
|
||||
@ -266,7 +266,7 @@ create objects. In such situations, cast arguments to force an exact match.
|
||||
<para>
|
||||
If one argument of a binary operator invocation is of the <type>unknown</type> type,
|
||||
then assume it is the same type as the other argument for this check.
|
||||
Invocations involving two <type>unknown</type> inputs, or a unary operator
|
||||
Invocations involving two <type>unknown</type> inputs, or a prefix operator
|
||||
with an <type>unknown</type> input, will never find a match at this step.
|
||||
</para>
|
||||
</step>
|
||||
|
@ -20,8 +20,8 @@
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<productname>PostgreSQL</productname> supports left unary, right
|
||||
unary, and binary operators. Operators can be
|
||||
<productname>PostgreSQL</productname> supports prefix
|
||||
and infix operators. Operators can be
|
||||
overloaded;<indexterm><primary>overloading</primary><secondary>operators</secondary></indexterm>
|
||||
that is, the same operator name can be used for different operators
|
||||
that have different numbers and types of operands. When a query is
|
||||
@ -64,9 +64,9 @@ SELECT (a + b) AS c FROM test_complex;
|
||||
</para>
|
||||
|
||||
<para>
|
||||
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
|
||||
<literal>rightarg</literal> (for right unary). The <literal>function</literal>
|
||||
We've shown how to create a binary operator here. To create a prefix
|
||||
operator, just omit the <literal>leftarg</literal>.
|
||||
The <literal>function</literal>
|
||||
clause and the argument clauses are the only required items in
|
||||
<command>CREATE OPERATOR</command>. The <literal>commutator</literal>
|
||||
clause shown in the example is an optional hint to the query
|
||||
@ -202,7 +202,7 @@ SELECT (a + b) AS c FROM test_complex;
|
||||
<para>
|
||||
Unlike commutators, a pair of unary operators could validly be marked
|
||||
as each other's negators; that would mean (A x) equals NOT (B x)
|
||||
for all x, or the equivalent for right unary operators.
|
||||
for all x.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
Reference in New Issue
Block a user