Hello
I did task from TODO: Add BETWEEN ASYMMETRIC/SYMMETRIC.
SELECT 2 BETWEEN 1 AND 5 -> true
SELECT 2 BETWEEN 5 AND 1 -> false
SELECT 2 BETWEEN SYMMETRIC 5 AND 1 -> true
this patch is based on Robert's B. Easter work from 2001 year.
http://archives.postgresql.org/pgsql-patches/2001-01/msg00022.php
it's trivial, only small change in parser.
Best regards
Pavel Stehule
diff -c -r --new-file pgsql.new/src/backend/parser/gram.y
pgsql.old/src/backend/parser/gram.y
*** pgsql.old/src/backend/parser/gram.y 2005-05-07 04:22:46.000000000 +0200
--- pgsql.new/src/backend/parser/gram.y 2005-06-01 00:05:37.000000000 +0200
***************
*** 338,344 ****
/* ordinary key words in alphabetical order */
%token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD AFTER
AGGREGATE ALL ALSO ALTER ANALYSE ANALYZE AND ANY ARRAY AS ASC
! ASSERTION ASSIGNMENT AT AUTHORIZATION
BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
BOOLEAN_P BOTH BY
--- 338,344 ----
/* ordinary key words in alphabetical order */
%token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD AFTER
AGGREGATE ALL ALSO ALTER ANALYSE ANALYZE AND ANY ARRAY AS ASC
! ASSERTION ASSIGNMENT ASYMMETRIC AT AUTHORIZATION
BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
BOOLEAN_P BOTH BY
***************
*** 399,405 ****
SAVEPOINT SCHEMA SCROLL SECOND_P SECURITY SELECT SEQUENCE
SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
SHOW SIMILAR SIMPLE SMALLINT SOME STABLE START STATEMENT
! STATISTICS STDIN STDOUT STORAGE STRICT_P SUBSTRING SYSID
TABLE TABLESPACE TEMP TEMPLATE TEMPORARY THEN TIME TIMESTAMP
TO TOAST TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
--- 399,406 ----
SAVEPOINT SCHEMA SCROLL SECOND_P SECURITY SELECT SEQUENCE
SERIALIZABLE SESSION SESSION_USER SET SETOF SHARE
SHOW SIMILAR SIMPLE SMALLINT SOME STABLE START STATEMENT
! STATISTICS STDIN STDOUT STORAGE STRICT_P SUBSTRING SYMMETRIC
! SYSID
TABLE TABLESPACE TEMP TEMPLATE TEMPORARY THEN TIME TIMESTAMP
TO TOAST TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
***************
*** 6341,6358 ****
{
$$ = (Node *)
makeSimpleA_Expr(AEXPR_OF, "!=", $1, (Node *) $6);
}
! | a_expr BETWEEN b_expr AND b_expr
%prec BETWEEN
{
$$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
! (Node *)
makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3),
! (Node *)
makeSimpleA_Expr(AEXPR_OP, "<=", $1, $5));
}
! | a_expr NOT BETWEEN b_expr AND b_expr %prec
BETWEEN
{
$$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
! (Node *)
makeSimpleA_Expr(AEXPR_OP, "<", $1, $4),
! (Node *)
makeSimpleA_Expr(AEXPR_OP, ">", $1, $6));
}
| a_expr IN_P in_expr
{
/* in_expr returns a SubLink or a list
of a_exprs */
--- 6342,6382 ----
{
$$ = (Node *)
makeSimpleA_Expr(AEXPR_OF, "!=", $1, (Node *) $6);
}
! | a_expr BETWEEN opt_asymmetric b_expr AND b_expr
%prec BETWEEN
{
$$ = (Node *) makeA_Expr(AEXPR_AND, NIL,
! (Node *)
makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4),
! (Node *)
makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6));
}
! | a_expr NOT BETWEEN opt_asymmetric b_expr AND b_expr
%prec BETWEEN
{
$$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
! (Node *)
makeSimpleA_Expr(AEXPR_OP, "<", $1, $5),
! (Node *)
makeSimpleA_Expr(AEXPR_OP, ">", $1, $7));
}
+
+ | a_expr BETWEEN SYMMETRIC b_expr AND b_expr
%prec BETWEEN
+ {
+ $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
+ (Node *) makeA_Expr(AEXPR_AND,
NIL,
+ (Node *)
makeSimpleA_Expr(AEXPR_OP, ">=", $1, $4),
+ (Node *)
makeSimpleA_Expr(AEXPR_OP, "<=", $1, $6)),
+ (Node *) makeA_Expr(AEXPR_AND,
NIL,
+ (Node *)
makeSimpleA_Expr(AEXPR_OP, ">=", $1, $6),
+ (Node *)
makeSimpleA_Expr(AEXPR_OP, "<=", $1, $4)));
+ }
+ | a_expr NOT BETWEEN SYMMETRIC b_expr AND b_expr
%prec BETWEEN
+ {
+ $$ = (Node *) makeA_Expr(AEXPR_OR, NIL,
+ (Node *) makeA_Expr(AEXPR_AND,
NIL,
+ (Node *)
makeSimpleA_Expr(AEXPR_OP, "<", $1, $5),
+ (Node *)
makeSimpleA_Expr(AEXPR_OP, ">", $1, $7)),
+ (Node *) makeA_Expr(AEXPR_AND,
NIL,
+ (Node *)
makeSimpleA_Expr(AEXPR_OP, "<", $1, $7),
+ (Node *)
makeSimpleA_Expr(AEXPR_OP, ">", $1, $5)));
+ }
+
+
| a_expr IN_P in_expr
{
/* in_expr returns a SubLink or a list
of a_exprs */
***************
*** 6451,6456 ****
--- 6475,6485 ----
}
;
+ opt_asymmetric: ASYMMETRIC
{}
+ | /*EMPTY*/
{}
+ ;
+
+
/*
* Restricted expressions
*
diff -c -r --new-file pgsql.old/src/backend/parser/keywords.c
pgsql.new/src/backend/parser/keywords.c
*** pgsql.old/src/backend/parser/keywords.c 2005-05-07 04:22:47.000000000
+0200
--- pgsql.new/src/backend/parser/keywords.c 2005-05-31 22:39:44.000000000
+0200
***************
*** 49,54 ****
--- 49,55 ----
{"asc", ASC},
{"assertion", ASSERTION},
{"assignment", ASSIGNMENT},
+ {"asymmetric", ASYMMETRIC},
{"at", AT},
{"authorization", AUTHORIZATION},
{"backward", BACKWARD},
***************
*** 296,301 ****
--- 297,303 ----
{"storage", STORAGE},
{"strict", STRICT_P},
{"substring", SUBSTRING},
+ {"symmetric", SYMMETRIC},
{"sysid", SYSID},
{"table", TABLE},
{"tablespace", TABLESPACE},
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq