apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
5.61k stars 1.05k forks source link

Inconsistent behavior of '+-' arithmetic operator on Boolean type #11175

Open 2010YOUY01 opened 3 weeks ago

2010YOUY01 commented 3 weeks ago

Describe the bug

Inconsistnecy is showed in the below queries, it's better to keep the behavior consistent (PostgreSQL reject them all during planning)

> select +true, +false;
+---------------+----------------+
| Boolean(true) | Boolean(false) |
+---------------+----------------+
| true          | false          |
+---------------+----------------+
1 row(s) fetched.
Elapsed 0.008 seconds.

> select -true;
Error during planning: Negation only supports numeric, interval and timestamp types
> select -false;
Error during planning: Negation only supports numeric, interval and timestamp types

PostgreSQL behavior:

postgres=# select +true;
ERROR:  operator does not exist: + boolean
LINE 1: select +true;
               ^
HINT:  No operator matches the given name and argument type. You might need to add an explicit type cast.
postgres=# select -true;
ERROR:  operator does not exist: - boolean
LINE 1: select -true;

To Reproduce

No response

Expected behavior

No response

Additional context

No response

alamb commented 3 weeks ago

I think it would be fine to have negate work for booleans (and basically be a noop as it seems in postgres)

Thank you for the report @2010YOUY01