dehowef opened a new issue, #1008:
URL: https://github.com/apache/age/issues/1008
**Describe the bug**
AGE relies on implicit casting to smoothly implement PG-type booleans. AG
types may be implicitly cast to a boolean type. This has proven to not be an
issue in most cases, but does cause unexpected behavior in
transform_BoolExpr(). transform_BoolExpr uses PG's coerce_to_boolean() to check
if agtypes can be cast to a boolean type, and because AGE allows implicit
castring, there are cases that do not throw an error where it normally would be
expected to.
In the case of logical gates, this causes the following unexpected behavior:
```
SELECT * from cypher('my_graph_name', $$
RETURN true OR 1
$$) as (a agtype);
```
The previous query would be expected to throw a type compatibility error,
but instead it returns 'TRUE'
Similarly,
```
SELECT * from cypher('my_graph_name', $$
RETURN FALSE AND 1
$$) as (a agtype);
```
would be expected to throw a type compatibility error, but instead it
returns FALSE.
The inverse of these two queries, RETURN 1 OR true, and RETURN 1 and false
throw an error:
```
ERROR: cannot cast agtype integer to type boolean
STATEMENT: SELECT * FROM cypher('empty', $$ RETURN 1 OR true $$) as (a
agtype);
ERROR: cannot cast agtype integer to type boolean
``
Because of the associativity of logical operators (left associativity), the
boolean expression is optimized to pass or fail as soon as either condition is
validated. But, this is an execution phase error.
The error that coerce_to_boolean would throw is:
```
ERROR: argument of OR must be type boolean, not type integer at
character 8
STATEMENT: SELECT 1 OR TRUE
ERROR: argument of OR must be type boolean, not type integer
```
which would be an error thrown during the transform phase rather than during
execution. Since AGE's constraint logic (WHERE, property constraints, etc),
rely on implicit boolean casting, resolving this specific edge case may require
modifying logic during the execution phase.
**How are you accessing AGE (Command line, driver, etc.)?**
- Command Line
**What data setup do we need to do?**
This can be run on an instance of AGE installed via command line with no
data setup required.
**What is the necessary configuration info needed?**
- Install AGE.
**What is the command that caused the error?**
Denoted above, but here is one of the problem commands stated again:
```pgsql
SELECT * from cypher('my_graph_name', $$
RETURN FALSE AND 1
$$) as (a agtype);
```
**Expected behavior**
We'd expect coerce_to_boolean or another function in the transform phase to
throw a type mismatch error, something along the lines of:
```
ERROR: argument of OR must be type boolean, not type integer at
character 8
STATEMENT: SELECT 1 OR TRUE
ERROR: argument of OR must be type boolean, not type integer
```
**Environment (please complete the following information):**
- Version: latest main branch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]