Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'BETWEEN AND', inclusive or exclusive? #207

Open
unknownzerx opened this issue Dec 29, 2017 · 2 comments
Open

'BETWEEN AND', inclusive or exclusive? #207

unknownzerx opened this issue Dec 29, 2017 · 2 comments

Comments

@unknownzerx
Copy link

Should 'BETWEEN AND' be inclusive or exclusive, or configurable by dialect?

@araddon
Copy link
Owner

araddon commented Dec 29, 2017

Thanks for the issue, let me find some unit-tests and examples from other dialects and implement in unit tests here.

@araddon
Copy link
Owner

araddon commented Dec 30, 2017

It appears that it is dialect specific but most dialects are inclusive https://english.stackexchange.com/questions/118402/when-is-between-inclusive-and-when-exclusive

Which means that currently this implementation is exclusive, but probably should be inclusive. Let me see if i can switch it without breaking too much.

mysql> SELECT 
    ->     1 BETWEEN 1 AND 3 AS a,
    ->     3 BETWEEN 1 AND 3 AS b,
    ->     3 BETWEEN 1 AND '3' AS c,
    ->     2 BETWEEN 3 and 1 AS d, 
    ->     3.0 BETWEEN 1 AND 3 as e,
    ->     3 BETWEEN NULL AND 1 as f,
    ->     3 BETWEEN NULL AND 4 AS g, 
    ->     CAST("2017-03-03" AS DATE) BETWEEN CAST("2017-01-03" AS DATE) AND CAST("2017-12-03" AS DATE) AS d1,
    ->     CAST("2015-03-03" AS DATE) BETWEEN CAST("2017-01-03" AS DATE) AND CAST("2017-12-03" AS DATE) AS d2,
    ->     CAST("2017-03-03" AS DATE) BETWEEN CAST("2017-01-03" AS DATE) AND "2017-12-03" AS d3
    ->     ;
+---+---+---+---+---+------+------+------+------+------+
| a | b | c | d | e | f    | g    | d1   | d2   | d3   |
+---+---+---+---+---+------+------+------+------+------+
| 1 | 1 | 1 | 0 | 1 |    0 | NULL |    1 |    0 |    1 |
+---+---+---+---+---+------+------+------+------+------+
1 row in set (0.00 sec)



postgres=# SELECT 
postgres-#     1 BETWEEN 1 AND 3 AS a,
postgres-#     3 BETWEEN 1 AND 3 AS b,
postgres-#     3 BETWEEN 1 AND '3' AS c,
postgres-#     2 BETWEEN 3 and 1 AS d, 
postgres-#     3.0 BETWEEN 1 AND 3 as e,
postgres-#     3 BETWEEN NULL AND 1 as f,
postgres-#     3 BETWEEN NULL AND 4 AS g;
 a | b | c | d | e | f | g 
---+---+---+---+---+---+---
 t | t | t | f | t | f | 
(1 row)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants