Re: [HACKERS] Operator definitions

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: [HACKERS] Operator definitions
Дата
Msg-id 199909281512.LAA19187@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: [HACKERS] Operator definitions  (Thomas Lockhart <lockhart@alumni.caltech.edu>)
Список pgsql-hackers
> > OK, I have applied a patch to fix all the operator cases for ^ and |.
> > This will be in 6.6.
> > The issue is that we want to specify precedence for the common math
> > operators, and I needed to be able to specify precedence for '|' so people
> > could do SELECT 'A' | 'B' | 'C'.
>
> I had already posted and applied a patch for the stable branch, since
> v6.5.2 was damaged wrt v6.5 functionality. The patch will also appear
> in RedHat's rpms for their RH6.1 release. I hadn't yet applied the
> patch to the main branch, but have it in my gram.y code where I'm
> working on join syntax.
>
> Can you compare your patch of the main branch with the very recent
> changes on the stable branch?
>
> Darn, back to cvs merge hell...
>

Man, there are tons of changes between the two.

Here are the changes I made.  I can easily back this out, and re-add
after you are done.

--
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: gram.y
===================================================================
RCS file: /usr/local/cvsroot/pgsql/src/backend/parser/gram.y,v
retrieving revision 2.100
retrieving revision 2.103
diff -c -r2.100 -r2.103
*** gram.y    1999/09/28 04:34:44    2.100
--- gram.y    1999/09/28 14:49:36    2.103
***************
*** 10,16 ****
   *
   *
   * IDENTIFICATION
!  *      $Header: /usr/local/cvsroot/pgsql/src/backend/parser/gram.y,v 2.100 1999/09/28 04:34:44 momjian Exp $
   *
   * HISTORY
   *      AUTHOR            DATE            MAJOR EVENT
--- 10,16 ----
   *
   *
   * IDENTIFICATION
!  *      $Header: /usr/local/cvsroot/pgsql/src/backend/parser/gram.y,v 2.103 1999/09/28 14:49:36 momjian Exp $
   *
   * HISTORY
   *      AUTHOR            DATE            MAJOR EVENT
***************
*** 977,982 ****
--- 977,984 ----
                  {    $$ = nconc( $1, lcons( makeString( "*"), $3)); }
              | default_expr '^' default_expr
                  {    $$ = nconc( $1, lcons( makeString( "^"), $3)); }
+             | default_expr '|' default_expr
+                 {    $$ = nconc( $1, lcons( makeString( "|"), $3)); }
              | default_expr '=' default_expr
                  {    elog(ERROR,"boolean expressions not supported in DEFAULT"); }
              | default_expr '<' default_expr
***************
*** 1127,1132 ****
--- 1129,1136 ----
                  {    $$ = nconc( $1, lcons( makeString( "*"), $3)); }
              | constraint_expr '^' constraint_expr
                  {    $$ = nconc( $1, lcons( makeString( "^"), $3)); }
+             | constraint_expr '|' constraint_expr
+                 {    $$ = nconc( $1, lcons( makeString( "|"), $3)); }
              | constraint_expr '=' constraint_expr
                  {    $$ = nconc( $1, lcons( makeString( "="), $3)); }
              | constraint_expr '<' constraint_expr
***************
*** 2042,2047 ****
--- 2046,2053 ----
          | '*'            { $$ = "*"; }
          | '/'            { $$ = "/"; }
          | '%'            { $$ = "%"; }
+         | '^'            { $$ = "^"; }
+         | '|'            { $$ = "|"; }
          | '<'            { $$ = "<"; }
          | '>'            { $$ = ">"; }
          | '='            { $$ = "="; }
***************
*** 3638,3643 ****
--- 3644,3651 ----
          | '*'                                { $$ = "*"; }
          | '/'                                { $$ = "/"; }
          | '%'                                { $$ = "%"; }
+         | '^'                                { $$ = "^"; }
+         | '|'                                { $$ = "|"; }
          ;

  sub_type:  ANY                                { $$ = ANY_SUBLINK; }
***************
*** 3672,3693 ****
                  {    $$ = makeA_Expr(OP, "%", NULL, $2); }
          | '^' a_expr
                  {    $$ = makeA_Expr(OP, "^", NULL, $2); }
          | a_expr '%'
                  {    $$ = makeA_Expr(OP, "%", $1, NULL); }
          | a_expr '^'
                  {    $$ = makeA_Expr(OP, "^", $1, NULL); }
          | a_expr '+' a_expr
                  {    $$ = makeA_Expr(OP, "+", $1, $3); }
          | a_expr '-' a_expr
                  {    $$ = makeA_Expr(OP, "-", $1, $3); }
          | a_expr '/' a_expr
                  {    $$ = makeA_Expr(OP, "/", $1, $3); }
          | a_expr '%' a_expr
                  {    $$ = makeA_Expr(OP, "%", $1, $3); }
-         | a_expr '*' a_expr
-                 {    $$ = makeA_Expr(OP, "*", $1, $3); }
          | a_expr '^' a_expr
                  {    $$ = makeA_Expr(OP, "^", $1, $3); }
          | a_expr '<' a_expr
                  {    $$ = makeA_Expr(OP, "<", $1, $3); }
          | a_expr '>' a_expr
--- 3680,3711 ----
                  {    $$ = makeA_Expr(OP, "%", NULL, $2); }
          | '^' a_expr
                  {    $$ = makeA_Expr(OP, "^", NULL, $2); }
+         | '|' a_expr
+                 {    $$ = makeA_Expr(OP, "|", NULL, $2); }
+         | ':' a_expr
+                 {    $$ = makeA_Expr(OP, ":", NULL, $2); }
+         | ';' a_expr
+                 {    $$ = makeA_Expr(OP, ";", NULL, $2); }
          | a_expr '%'
                  {    $$ = makeA_Expr(OP, "%", $1, NULL); }
          | a_expr '^'
                  {    $$ = makeA_Expr(OP, "^", $1, NULL); }
+         | a_expr '|'
+                 {    $$ = makeA_Expr(OP, "|", $1, NULL); }
          | a_expr '+' a_expr
                  {    $$ = makeA_Expr(OP, "+", $1, $3); }
          | a_expr '-' a_expr
                  {    $$ = makeA_Expr(OP, "-", $1, $3); }
+         | a_expr '*' a_expr
+                 {    $$ = makeA_Expr(OP, "*", $1, $3); }
          | a_expr '/' a_expr
                  {    $$ = makeA_Expr(OP, "/", $1, $3); }
          | a_expr '%' a_expr
                  {    $$ = makeA_Expr(OP, "%", $1, $3); }
          | a_expr '^' a_expr
                  {    $$ = makeA_Expr(OP, "^", $1, $3); }
+         | a_expr '|' a_expr
+                 {    $$ = makeA_Expr(OP, "|", $1, $3); }
          | a_expr '<' a_expr
                  {    $$ = makeA_Expr(OP, "<", $1, $3); }
          | a_expr '>' a_expr
***************
*** 3701,3712 ****

          | a_expr '=' a_expr
                  {    $$ = makeA_Expr(OP, "=", $1, $3); }
-         | ':' a_expr
-                 {    $$ = makeA_Expr(OP, ":", NULL, $2); }
-         | ';' a_expr
-                 {    $$ = makeA_Expr(OP, ";", NULL, $2); }
-         | '|' a_expr
-                 {    $$ = makeA_Expr(OP, "|", NULL, $2); }
          | a_expr TYPECAST Typename
                  {
                      $$ = (Node *)$1;
--- 3719,3724 ----
***************
*** 4089,4094 ****
--- 4101,4116 ----
                      n->subselect = $4;
                      $$ = (Node *)n;
                  }
+         | a_expr '*' '(' SubSelect ')'
+                 {
+                     SubLink *n = makeNode(SubLink);
+                     n->lefthand = lcons($1, NULL);
+                     n->oper = lcons("*",NIL);
+                     n->useor = false;
+                     n->subLinkType = EXPR_SUBLINK;
+                     n->subselect = $4;
+                     $$ = (Node *)n;
+                 }
          | a_expr '/' '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
***************
*** 4109,4124 ****
                      n->subselect = $4;
                      $$ = (Node *)n;
                  }
!         | a_expr '*' '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
                      n->lefthand = lcons($1, NULL);
!                     n->oper = lcons("*",NIL);
                      n->useor = false;
                      n->subLinkType = EXPR_SUBLINK;
                      n->subselect = $4;
                      $$ = (Node *)n;
                  }
          | a_expr '<' '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
--- 4131,4156 ----
                      n->subselect = $4;
                      $$ = (Node *)n;
                  }
!         | a_expr '^' '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
                      n->lefthand = lcons($1, NULL);
!                     n->oper = lcons("^",NIL);
                      n->useor = false;
                      n->subLinkType = EXPR_SUBLINK;
                      n->subselect = $4;
                      $$ = (Node *)n;
                  }
+         | a_expr '|' '(' SubSelect ')'
+                 {
+                     SubLink *n = makeNode(SubLink);
+                     n->lefthand = lcons($1, NULL);
+                     n->oper = lcons("|",NIL);
+                     n->useor = false;
+                     n->subLinkType = EXPR_SUBLINK;
+                     n->subselect = $4;
+                     $$ = (Node *)n;
+                 }
          | a_expr '<' '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
***************
*** 4179,4184 ****
--- 4211,4226 ----
                      n->subselect = $5;
                      $$ = (Node *)n;
                  }
+         | a_expr '*' ANY '(' SubSelect ')'
+                 {
+                     SubLink *n = makeNode(SubLink);
+                     n->lefthand = lcons($1,NIL);
+                     n->oper = lcons("*",NIL);
+                     n->useor = false;
+                     n->subLinkType = ANY_SUBLINK;
+                     n->subselect = $5;
+                     $$ = (Node *)n;
+                 }
          | a_expr '/' ANY '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
***************
*** 4199,4209 ****
                      n->subselect = $5;
                      $$ = (Node *)n;
                  }
!         | a_expr '*' ANY '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
                      n->lefthand = lcons($1,NIL);
!                     n->oper = lcons("*",NIL);
                      n->useor = false;
                      n->subLinkType = ANY_SUBLINK;
                      n->subselect = $5;
--- 4241,4261 ----
                      n->subselect = $5;
                      $$ = (Node *)n;
                  }
!         | a_expr '^' ANY '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
                      n->lefthand = lcons($1,NIL);
!                     n->oper = lcons("^",NIL);
!                     n->useor = false;
!                     n->subLinkType = ANY_SUBLINK;
!                     n->subselect = $5;
!                     $$ = (Node *)n;
!                 }
!         | a_expr '|' ANY '(' SubSelect ')'
!                 {
!                     SubLink *n = makeNode(SubLink);
!                     n->lefthand = lcons($1,NIL);
!                     n->oper = lcons("|",NIL);
                      n->useor = false;
                      n->subLinkType = ANY_SUBLINK;
                      n->subselect = $5;
***************
*** 4269,4274 ****
--- 4321,4336 ----
                      n->subselect = $5;
                      $$ = (Node *)n;
                  }
+         | a_expr '*' ALL '(' SubSelect ')'
+                 {
+                     SubLink *n = makeNode(SubLink);
+                     n->lefthand = lcons($1, NULL);
+                     n->oper = lcons("*",NIL);
+                     n->useor = false;
+                     n->subLinkType = ALL_SUBLINK;
+                     n->subselect = $5;
+                     $$ = (Node *)n;
+                 }
          | a_expr '/' ALL '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
***************
*** 4289,4299 ****
                      n->subselect = $5;
                      $$ = (Node *)n;
                  }
!         | a_expr '*' ALL '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
                      n->lefthand = lcons($1, NULL);
!                     n->oper = lcons("*",NIL);
                      n->useor = false;
                      n->subLinkType = ALL_SUBLINK;
                      n->subselect = $5;
--- 4351,4371 ----
                      n->subselect = $5;
                      $$ = (Node *)n;
                  }
!         | a_expr '^' ALL '(' SubSelect ')'
                  {
                      SubLink *n = makeNode(SubLink);
                      n->lefthand = lcons($1, NULL);
!                     n->oper = lcons("^",NIL);
!                     n->useor = false;
!                     n->subLinkType = ALL_SUBLINK;
!                     n->subselect = $5;
!                     $$ = (Node *)n;
!                 }
!         | a_expr '|' ALL '(' SubSelect ')'
!                 {
!                     SubLink *n = makeNode(SubLink);
!                     n->lefthand = lcons($1, NULL);
!                     n->oper = lcons("|",NIL);
                      n->useor = false;
                      n->subLinkType = ALL_SUBLINK;
                      n->subselect = $5;
***************
*** 4363,4390 ****
                  {    $$ = makeA_Expr(OP, "%", NULL, $2); }
          | '^' b_expr
                  {    $$ = makeA_Expr(OP, "^", NULL, $2); }
          | b_expr '%'
                  {    $$ = makeA_Expr(OP, "%", $1, NULL); }
          | b_expr '^'
                  {    $$ = makeA_Expr(OP, "^", $1, NULL); }
          | b_expr '+' b_expr
                  {    $$ = makeA_Expr(OP, "+", $1, $3); }
          | b_expr '-' b_expr
                  {    $$ = makeA_Expr(OP, "-", $1, $3); }
          | b_expr '/' b_expr
                  {    $$ = makeA_Expr(OP, "/", $1, $3); }
          | b_expr '%' b_expr
                  {    $$ = makeA_Expr(OP, "%", $1, $3); }
-         | b_expr '*' b_expr
-                 {    $$ = makeA_Expr(OP, "*", $1, $3); }
          | b_expr '^' b_expr
                  {    $$ = makeA_Expr(OP, "^", $1, $3); }
!         | ':' b_expr
!                 {    $$ = makeA_Expr(OP, ":", NULL, $2); }
!         | ';' b_expr
!                 {    $$ = makeA_Expr(OP, ";", NULL, $2); }
!         | '|' b_expr
!                 {    $$ = makeA_Expr(OP, "|", NULL, $2); }
          | b_expr TYPECAST Typename
                  {
                      $$ = (Node *)$1;
--- 4435,4466 ----
                  {    $$ = makeA_Expr(OP, "%", NULL, $2); }
          | '^' b_expr
                  {    $$ = makeA_Expr(OP, "^", NULL, $2); }
+         | '|' b_expr
+                 {    $$ = makeA_Expr(OP, "|", NULL, $2); }
+         | ':' b_expr
+                 {    $$ = makeA_Expr(OP, ":", NULL, $2); }
+         | ';' b_expr
+                 {    $$ = makeA_Expr(OP, ";", NULL, $2); }
          | b_expr '%'
                  {    $$ = makeA_Expr(OP, "%", $1, NULL); }
          | b_expr '^'
                  {    $$ = makeA_Expr(OP, "^", $1, NULL); }
+         | b_expr '|'
+                 {    $$ = makeA_Expr(OP, "|", $1, NULL); }
          | b_expr '+' b_expr
                  {    $$ = makeA_Expr(OP, "+", $1, $3); }
          | b_expr '-' b_expr
                  {    $$ = makeA_Expr(OP, "-", $1, $3); }
+         | b_expr '*' b_expr
+                 {    $$ = makeA_Expr(OP, "*", $1, $3); }
          | b_expr '/' b_expr
                  {    $$ = makeA_Expr(OP, "/", $1, $3); }
          | b_expr '%' b_expr
                  {    $$ = makeA_Expr(OP, "%", $1, $3); }
          | b_expr '^' b_expr
                  {    $$ = makeA_Expr(OP, "^", $1, $3); }
!         | b_expr '|' b_expr
!                 {    $$ = makeA_Expr(OP, "|", $1, $3); }
          | b_expr TYPECAST Typename
                  {
                      $$ = (Node *)$1;

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Thomas Lockhart
Дата:
Сообщение: Re: [HACKERS] Operator definitions
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] Operator definitions