Describe the bug

No response

To Reproduce

dev=> select 1 = (array[1])[1];
ERROR:  QueryError: Feature is not yet implemented: Equal[Int32, List]
Tracking issue: https://github.com/risingwavelabs/risingwave/issues/112

Expected behavior

pg:

postgres=# select 1 = (array[1])[1];
 ?column?
----------
 t
(1 row)

Additional context

No response

4

To clarify, the desired precedence is as follows:

select 1 = (array[1])[1] should evaluate (array[1])[1] first, resulting in select 1 = 1, which can be compared.

The current behaviour is:

select 1 = (array[1])[1] is evaluating select 1 = array[1] first, resulting in Equal[Int32, List].

We can achieve the desired behaviour if we give array access a higher precedence.

Interestingly the following works:

select (array[1])[1] = 1;
 ?column?
----------
 t
(1 row)

select (array[3])[1] = 1;
 ?column?
----------
 f
(1 row)

The following works as expected since we "overwriting" the precedence using ():

select 1 = ((array[1])[1]);
 ?column?
----------
 t
(1 row)

This has nothing to do with the equality operator. This is true for the other comparison operators as well. If the array access is on the LHS it works.

# array access on LHS
dev=> select (array[1])[1] > 1;
 ?column?
----------
 f
(1 row)

dev=> select (array[1])[1] < 1;
 ?column?
----------
 f
(1 row)

dev=> select (array[1])[1] <= 1;
 ?column?
----------
 t
(1 row)

dev=> select (array[1])[1] >= 1;
 ?column?
----------
 t
(1 row)

dev=> select (array[1])[1] != 1;
 ?column?
----------
 f
(1 row)

# array access on RHS 
select 1 = (array[3])[1];
ERROR:  QueryError: Feature is not yet implemented: Equal[Int32, List]

select 1 < (array[3])[1];
ERROR:  QueryError: Feature is not yet implemented: LessThan[Int32, List]

select 1 > (array[3])[1];
ERROR:  QueryError: Feature is not yet implemented: GreaterThan[Int32, List]

select 1 >= (array[3])[1];
ERROR:  QueryError: Feature is not yet implemented: GreaterThanOrEqual[Int32, List]

select 1 != (array[3])[1];
ERROR:  QueryError: Feature is not yet implemented: NotEqual[Int32, List]
1

I did not find a RW documentation about what the desired operator precedence is. I assume that it is the same as in Postgres (see PSQL Docs). Please correct me if I am wrong @xxchan @fuyufjh

1

Yes, we try to be compatible with PG if not otherwise specified

1

Different ASTs for the working and broken query respectively

select (array[1])[1] >= 1; # working
AST: [Query(Query { with: None, body: Select(Select { distinct: false, projection: [UnnamedExpr(BinaryOp { left: ArrayIndex { obj: Nested(Array([Value(Number("1"))])), index: Value(Number("1")) }, op: GtEq, right: Value(Number("1")) })], from: [], lateral_views: [], selection: None, group_by: [], having: None }), order_by: [], limit: None, offset: None, fetch: None })]

select 1 <= (array[1])[1]; # broken
AST: [Query(Query { with: None, body: Select(Select { distinct: false, projection: [UnnamedExpr(ArrayIndex { obj: BinaryOp { left: Value(Number("1")), op: LtEq, right: Nested(Array([Value(Number("1"))])) }, index: Value(Number("1")) })], from: [], lateral_views: [], selection: None, group_by: [], having: None }), order_by: [], limit: None, offset: None, fetch: None })]

As you can see the broken query has the array index operator as the root node, instead of the binary >= operator.

0

PR is merged (see PR)

0
© 2022 pullanswer.com - All rights reserved.