Hello

two years a operator "=>" is marked as deprecated (from PostgreSQL 9.2).

Isn't time to use it for named parameters now (for PostgreSQL 9.5) ?

I am sending a implementation where syntax based on "=>" symbol is second
(but preferred) variant of ":=" syntax .. syntax ":=" will be supported
still.

Here is a patch

comments, notices?

Regards

Pavel
commit 857c079d6b8030c575da129bb142860e8f6f951e
Author: Pavel Stehule <pavel.steh...@gooddata.com>
Date:   Sun Jan 18 02:25:48 2015 +0100

    initial implementation

diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 5e7b000..c33190e 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -6785,7 +6785,7 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
          Create interval from years, months, weeks, days, hours, minutes and
          seconds fields
         </entry>
-        <entry><literal>make_interval(days := 10)</literal></entry>
+        <entry><literal>make_interval(days => 10)</literal></entry>
         <entry><literal>10 days</literal></entry>
        </row>
 
diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml
index 4b81b08..d30db6a 100644
--- a/doc/src/sgml/syntax.sgml
+++ b/doc/src/sgml/syntax.sgml
@@ -2599,7 +2599,7 @@ SELECT concat_lower_or_upper('Hello', 'World');
      <literal>:=</literal> to separate it from the argument expression.
      For example:
 <screen>
-SELECT concat_lower_or_upper(a := 'Hello', b := 'World');
+SELECT concat_lower_or_upper(a => 'Hello', b => 'World');
  concat_lower_or_upper 
 -----------------------
  hello world
@@ -2610,13 +2610,24 @@ SELECT concat_lower_or_upper(a := 'Hello', b := 'World');
      using named notation is that the arguments may be specified in any
      order, for example:
 <screen>
-SELECT concat_lower_or_upper(a := 'Hello', b := 'World', uppercase := true);
+SELECT concat_lower_or_upper(a => 'Hello', b => 'World', uppercase => true);
  concat_lower_or_upper 
 -----------------------
  HELLO WORLD
 (1 row)
 
-SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World');
+SELECT concat_lower_or_upper(a => 'Hello', uppercase => true, b => 'World');
+ concat_lower_or_upper 
+-----------------------
+ HELLO WORLD
+(1 row)
+</screen>
+    </para>
+
+    <para>
+      Older syntax based on ":=" symbol is still supported:
+<screen>
+    SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World');
  concat_lower_or_upper 
 -----------------------
  HELLO WORLD
@@ -2638,7 +2649,7 @@ SELECT concat_lower_or_upper(a := 'Hello', uppercase := true, b := 'World');
     already mentioned, named arguments cannot precede positional arguments.
     For example:
 <screen>
-SELECT concat_lower_or_upper('Hello', 'World', uppercase := true);
+SELECT concat_lower_or_upper('Hello', 'World', uppercase => true);
  concat_lower_or_upper 
 -----------------------
  HELLO WORLD
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index f40504c..264e5ff 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -776,14 +776,14 @@ SELECT mleast(VARIADIC ARRAY[]::numeric[]);
      <literal>VARIADIC</>.  For example, this will work:
 
 <screen>
-SELECT mleast(VARIADIC arr := ARRAY[10, -1, 5, 4.4]);
+SELECT mleast(VARIADIC arr => ARRAY[10, -1, 5, 4.4]);
 </screen>
 
      but not these:
 
 <screen>
-SELECT mleast(arr := 10);
-SELECT mleast(arr := ARRAY[10, -1, 5, 4.4]);
+SELECT mleast(arr => 10);
+SELECT mleast(arr => ARRAY[10, -1, 5, 4.4]);
 </screen>
     </para>
    </sect2>
diff --git a/src/backend/commands/operatorcmds.c b/src/backend/commands/operatorcmds.c
index 2996019..2d26345 100644
--- a/src/backend/commands/operatorcmds.c
+++ b/src/backend/commands/operatorcmds.c
@@ -93,9 +93,8 @@ DefineOperator(List *names, List *parameters)
 	 * as the name of a user-defined operator.
 	 */
 	if (strcmp(oprName, "=>") == 0)
-		ereport(WARNING,
-				(errmsg("=> is deprecated as an operator name"),
-				 errdetail("This name may be disallowed altogether in future versions of PostgreSQL.")));
+		ereport(ERROR,
+				(errmsg("=> is disallowed as an operator name")));
 
 	/* Check we have creation rights in target namespace */
 	aclresult = pg_namespace_aclcheck(oprNamespace, GetUserId(), ACL_CREATE);
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 36dac29..6a02dcc 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -531,7 +531,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
  */
 %token <str>	IDENT FCONST SCONST BCONST XCONST Op
 %token <ival>	ICONST PARAM
-%token			TYPECAST DOT_DOT COLON_EQUALS
+%token			TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
 
 /*
  * If you want to make any keyword changes, update the keyword table in
@@ -12557,6 +12557,15 @@ func_arg_expr:  a_expr
 					na->location = @1;
 					$$ = (Node *) na;
 				}
+			| param_name EQUALS_GREATER a_expr
+				{
+					NamedArgExpr *na = makeNode(NamedArgExpr);
+					na->name = $1;
+					na->arg = (Expr *) $3;
+					na->argnumber = -1;		/* until determined */
+					na->location = @1;
+					$$ = (Node *) na;
+				}
 		;
 
 type_list:	Typename								{ $$ = list_make1($1); }
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index 21a6f30..743df71 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -334,6 +334,7 @@ identifier		{ident_start}{ident_cont}*
 typecast		"::"
 dot_dot			\.\.
 colon_equals	":="
+equals_greater	"=>"
 
 /*
  * "self" is the set of chars that should be returned as single-character
@@ -808,6 +809,11 @@ other			.
 					return COLON_EQUALS;
 				}
 
+{equals_greater}	{
+					SET_YYLLOC();
+					return EQUALS_GREATER;
+				}
+
 {self}			{
 					SET_YYLLOC();
 					return yytext[0];
diff --git a/src/test/regress/expected/create_operator.out b/src/test/regress/expected/create_operator.out
index 2e6c764..3a216c2 100644
--- a/src/test/regress/expected/create_operator.out
+++ b/src/test/regress/expected/create_operator.out
@@ -29,13 +29,14 @@ CREATE OPERATOR #%# (
 -- Test comments
 COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
 ERROR:  operator does not exist: integer ######
--- Show deprecated message. => is deprecated now
+-- => is disallowed now
 CREATE OPERATOR => (
    leftarg = int8,		-- right unary
    procedure = numeric_fac
 );
-WARNING:  => is deprecated as an operator name
-DETAIL:  This name may be disallowed altogether in future versions of PostgreSQL.
+ERROR:  syntax error at or near "=>"
+LINE 1: CREATE OPERATOR => (
+                        ^
 -- Should fail. CREATE OPERATOR requires USAGE on SCHEMA
 BEGIN TRANSACTION;
 CREATE ROLE regress_rol_op1;
diff --git a/src/test/regress/expected/polymorphism.out b/src/test/regress/expected/polymorphism.out
index 27b2879..987b3ee 100644
--- a/src/test/regress/expected/polymorphism.out
+++ b/src/test/regress/expected/polymorphism.out
@@ -1356,6 +1356,73 @@ select dfunc('a'::text, 'b', flag := true); -- mixed notation
  a
 (1 row)
 
+-- ansi/sql syntax
+select dfunc(a => 1, b => 2);
+ dfunc 
+-------
+     1
+(1 row)
+
+select dfunc(a => 'a'::text, b => 'b');
+ dfunc 
+-------
+ a
+(1 row)
+
+select dfunc(a => 'a'::text, b => 'b', flag => false); -- named notation
+ dfunc 
+-------
+ b
+(1 row)
+
+select dfunc(b => 'b'::text, a => 'a'); -- named notation with default
+ dfunc 
+-------
+ a
+(1 row)
+
+select dfunc(a => 'a'::text, flag => true); -- named notation with default
+ dfunc 
+-------
+ a
+(1 row)
+
+select dfunc(a => 'a'::text, flag => false); -- named notation with default
+ dfunc 
+-------
+ 
+(1 row)
+
+select dfunc(b => 'b'::text, a => 'a', flag => true); -- named notation
+ dfunc 
+-------
+ a
+(1 row)
+
+select dfunc('a'::text, 'b', false); -- full positional notation
+ dfunc 
+-------
+ b
+(1 row)
+
+select dfunc('a'::text, 'b', flag => false); -- mixed notation
+ dfunc 
+-------
+ b
+(1 row)
+
+select dfunc('a'::text, 'b', true); -- full positional notation
+ dfunc 
+-------
+ a
+(1 row)
+
+select dfunc('a'::text, 'b', flag => true); -- mixed notation
+ dfunc 
+-------
+ a
+(1 row)
+
 -- check reverse-listing of named-arg calls
 CREATE VIEW dfview AS
    SELECT q1, q2,
diff --git a/src/test/regress/sql/create_operator.sql b/src/test/regress/sql/create_operator.sql
index f7a372a..0e5d635 100644
--- a/src/test/regress/sql/create_operator.sql
+++ b/src/test/regress/sql/create_operator.sql
@@ -35,7 +35,7 @@ CREATE OPERATOR #%# (
 -- Test comments
 COMMENT ON OPERATOR ###### (int4, NONE) IS 'bad right unary';
 
--- Show deprecated message. => is deprecated now
+-- => is disallowed now
 CREATE OPERATOR => (
    leftarg = int8,		-- right unary
    procedure = numeric_fac
diff --git a/src/test/regress/sql/polymorphism.sql b/src/test/regress/sql/polymorphism.sql
index 3d8dd1e..72f6cb5 100644
--- a/src/test/regress/sql/polymorphism.sql
+++ b/src/test/regress/sql/polymorphism.sql
@@ -748,6 +748,22 @@ select dfunc('a'::text, 'b', flag := false); -- mixed notation
 select dfunc('a'::text, 'b', true); -- full positional notation
 select dfunc('a'::text, 'b', flag := true); -- mixed notation
 
+-- ansi/sql syntax
+select dfunc(a => 1, b => 2);
+select dfunc(a => 'a'::text, b => 'b');
+select dfunc(a => 'a'::text, b => 'b', flag => false); -- named notation
+
+select dfunc(b => 'b'::text, a => 'a'); -- named notation with default
+select dfunc(a => 'a'::text, flag => true); -- named notation with default
+select dfunc(a => 'a'::text, flag => false); -- named notation with default
+select dfunc(b => 'b'::text, a => 'a', flag => true); -- named notation
+
+select dfunc('a'::text, 'b', false); -- full positional notation
+select dfunc('a'::text, 'b', flag => false); -- mixed notation
+select dfunc('a'::text, 'b', true); -- full positional notation
+select dfunc('a'::text, 'b', flag => true); -- mixed notation
+
+
 -- check reverse-listing of named-arg calls
 CREATE VIEW dfview AS
    SELECT q1, q2,
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to