SeaQL/sea-query

Support postgres Array constructor as function

Opened this issue · 0 comments

Motivation

I want to be able to construct a postgres array using the Array constructor:

SELECT ARRAY[3, 4, 5 + 6];

Notice that the elements are expressions rather than simply values.

Proposed Solutions

Allow functions to use either square brackets ([ and ]) or ordinary parentheses (( and )) as their invocation method. The default should be parentheses, with only a few operators or functions requiring square brackets.

Additional Information

Unfortunately, the while the current Value type supports arrays, it does not support embedding expressions in the array constructor.

This wouldn't be such a big limitation if we could work around this using custom expressions, but even this isn't possible:

let array_expr = sea_query::Expr::cust_with_exprs(
    "ARRAY [ $, $, $, $ ]",
    [
        "a".into(), "b".into(), "c".into(), "d".into()
    ]
);

doesn't produce the expected outcome when building because the square brackets are apparently interpreted as string delimiters when tokenizing.