From f1f221312ccc282e644dd2ce93cc3b1e6ace6a40 Mon Sep 17 00:00:00 2001
From: Mark Dilger <mark.dilger@enterprisedb.com>
Date: Thu, 27 Aug 2020 08:38:56 -0700
Subject: [PATCH v2] Adding deprecation notices.

This deprecates all three of:

  Postfix factorial operator (!)
  Prefix factorial operator (!!)
  Unary right (postfix) operators
---
 doc/src/sgml/func.sgml                |  7 +++----
 doc/src/sgml/ref/alter_opfamily.sgml  |  7 +++++++
 doc/src/sgml/ref/create_opclass.sgml  |  7 +++++++
 doc/src/sgml/ref/create_operator.sgml | 17 ++++++++++++++-
 doc/src/sgml/ref/drop_operator.sgml   |  2 +-
 doc/src/sgml/typeconv.sgml            |  2 +-
 doc/src/sgml/xoper.sgml               | 30 +++++++++++++++++++++------
 src/include/catalog/pg_operator.dat   |  4 ++--
 src/include/catalog/pg_proc.dat       |  2 +-
 9 files changed, 62 insertions(+), 16 deletions(-)

diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index bbbffd9d5b..b1bb6ff8f4 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -1054,7 +1054,7 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
         <returnvalue>numeric</returnvalue>
        </para>
        <para>
-        Factorial
+        Factorial (as a postfix operator, deprecated, use <link linkend="factorial">factorial()</link> instead)
        </para>
        <para>
         <literal>5 !</literal>
@@ -1068,14 +1068,13 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
         <returnvalue>numeric</returnvalue>
        </para>
        <para>
-        Factorial (as a prefix operator)
+        Factorial (as a prefix operator, deprecated, use <link linkend="factorial">factorial()</link> instead)
        </para>
        <para>
         <literal>!! 5</literal>
         <returnvalue>120</returnvalue>
        </para></entry>
       </row>
-
       <row>
        <entry role="func_table_entry"><para role="func_signature">
         <literal>@</literal> <replaceable>numeric_type</replaceable>
@@ -1348,7 +1347,7 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
       </row>
 
       <row>
-       <entry role="func_table_entry"><para role="func_signature">
+       <entry role="func_table_entry" id="factorial"><para role="func_signature">
         <indexterm>
          <primary>factorial</primary>
         </indexterm>
diff --git a/doc/src/sgml/ref/alter_opfamily.sgml b/doc/src/sgml/ref/alter_opfamily.sgml
index 4ac1cca95a..9b3064a5fe 100644
--- a/doc/src/sgml/ref/alter_opfamily.sgml
+++ b/doc/src/sgml/ref/alter_opfamily.sgml
@@ -146,6 +146,13 @@ ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="
       must always be specified.
      </para>
 
+     <note>
+      <para>
+       Right unary, also called postfix, operators are deprecated and will be
+       removed in <productname>PostgreSQL</productname> version 14.
+      </para>
+     </note>
+
      <para>
       In an <literal>ADD FUNCTION</literal> clause, the operand data type(s) the
       function is intended to support, if different from
diff --git a/doc/src/sgml/ref/create_opclass.sgml b/doc/src/sgml/ref/create_opclass.sgml
index f42fb6494c..e207f05132 100644
--- a/doc/src/sgml/ref/create_opclass.sgml
+++ b/doc/src/sgml/ref/create_opclass.sgml
@@ -166,6 +166,13 @@ CREATE OPERATOR CLASS <replaceable class="parameter">name</replaceable> [ DEFAUL
       as the operator class's data type.
      </para>
 
+     <note>
+      <para>
+       Right unary, also called postfix, operators are deprecated and will be
+       removed in <productname>PostgreSQL</productname> version 14.
+      </para>
+     </note>
+
      <para>
       In a <literal>FUNCTION</literal> clause, the operand data type(s) the
       function is intended to support, if different from
diff --git a/doc/src/sgml/ref/create_operator.sgml b/doc/src/sgml/ref/create_operator.sgml
index d5c385c087..8374641ba4 100644
--- a/doc/src/sgml/ref/create_operator.sgml
+++ b/doc/src/sgml/ref/create_operator.sgml
@@ -87,11 +87,18 @@ CREATE OPERATOR <replaceable>name</replaceable> (
 
   <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
+   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>
    The <replaceable class="parameter">function_name</replaceable>
    function must have been previously defined using <command>CREATE
@@ -165,6 +172,14 @@ CREATE OPERATOR <replaceable>name</replaceable> (
         The data type of the operator's right operand, if any.
         This option would be omitted for a right-unary operator.
        </para>
+
+       <note>
+        <para>
+         Right unary, also called postfix, operators are deprecated and will be
+         removed in <productname>PostgreSQL</productname> version 14.
+        </para>
+       </note>
+
       </listitem>
      </varlistentry>
 
diff --git a/doc/src/sgml/ref/drop_operator.sgml b/doc/src/sgml/ref/drop_operator.sgml
index 2dff050ecf..10d2b0b23b 100644
--- a/doc/src/sgml/ref/drop_operator.sgml
+++ b/doc/src/sgml/ref/drop_operator.sgml
@@ -121,7 +121,7 @@ DROP OPERATOR ~ (none, bit);
   </para>
 
   <para>
-   Remove the right unary factorial operator <literal>x!</literal>
+   Remove the deprecated right unary factorial operator <literal>x!</literal>
    for type <type>bigint</type>:
 <programlisting>
 DROP OPERATOR ! (bigint, none);
diff --git a/doc/src/sgml/typeconv.sgml b/doc/src/sgml/typeconv.sgml
index 8900d0eb38..9312f37c64 100644
--- a/doc/src/sgml/typeconv.sgml
+++ b/doc/src/sgml/typeconv.sgml
@@ -357,7 +357,7 @@ Some examples follow.
 <title>Factorial Operator Type Resolution</title>
 
 <para>
-There is only one factorial operator (postfix <literal>!</literal>)
+There is a deprecated factorial operator (postfix <literal>!</literal>)
 defined in the standard catalog, and it takes an argument of type
 <type>bigint</type>.
 The scanner assigns an initial type of <type>integer</type> to the argument
diff --git a/doc/src/sgml/xoper.sgml b/doc/src/sgml/xoper.sgml
index 56b08491c9..847f8701d0 100644
--- a/doc/src/sgml/xoper.sgml
+++ b/doc/src/sgml/xoper.sgml
@@ -66,12 +66,23 @@ SELECT (a + b) AS c FROM test_complex;
   <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>
-   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
-   optimizer.  Further details about <literal>commutator</literal> and other
-   optimizer hints appear in the next section.
+   <literal>rightarg</literal> (for right unary).
+  </para>
+
+  <note>
+   <para>
+    Right unary, also called postfix, operators are deprecated and will be
+    removed in <productname>PostgreSQL</productname> version 14.
+   </para>
+  </note>
+
+  <para>
+   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 optimizer.  Further details about
+   <literal>commutator</literal> and other optimizer hints appear in the next
+   section.
   </para>
  </sect1>
 
@@ -205,6 +216,13 @@ SELECT (a + b) AS c FROM test_complex;
     for all x, or the equivalent for right unary operators.
    </para>
 
+   <note>
+    <para>
+     Right unary, also called postfix, operators are deprecated and will be
+     removed in <productname>PostgreSQL</productname> version 14.
+    </para>
+   </note>
+
    <para>
     An operator's negator must have the same left and/or right operand types
     as the operator to be defined, so just as with <literal>COMMUTATOR</literal>, only the operator
diff --git a/src/include/catalog/pg_operator.dat b/src/include/catalog/pg_operator.dat
index 5b0e063655..0d013a7fd1 100644
--- a/src/include/catalog/pg_operator.dat
+++ b/src/include/catalog/pg_operator.dat
@@ -218,10 +218,10 @@
   oprname => '>=', oprleft => 'xid8', oprright => 'xid8', oprresult => 'bool',
   oprcom => '<=(xid8,xid8)', oprnegate => '<(xid8,xid8)', oprcode => 'xid8ge',
   oprrest => 'scalargesel', oprjoin => 'scalargejoinsel' },
-{ oid => '388', descr => 'factorial',
+{ oid => '388', descr => 'deprecated, use factorial instead',
   oprname => '!', oprkind => 'r', oprleft => 'int8', oprright => '0',
   oprresult => 'numeric', oprcode => 'numeric_fac' },
-{ oid => '389', descr => 'deprecated, use ! instead',
+{ oid => '389', descr => 'deprecated, use factorial instead',
   oprname => '!!', oprkind => 'l', oprleft => '0', oprright => 'int8',
   oprresult => 'numeric', oprcode => 'numeric_fac' },
 { oid => '385', descr => 'equal',
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 27989971db..a08f4cf449 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -327,7 +327,7 @@
 { oid => '110', descr => 'I/O',
   proname => 'unknownout', prorettype => 'cstring', proargtypes => 'unknown',
   prosrc => 'unknownout' },
-{ oid => '111',
+{ oid => '111', descr => 'factorial',
   proname => 'numeric_fac', prorettype => 'numeric', proargtypes => 'int8',
   prosrc => 'numeric_fac' },
 
-- 
2.21.1 (Apple Git-122.3)

