Skip to content

Conversation

@griffio
Copy link
Collaborator

@griffio griffio commented Nov 11, 2025

🚧 🕳️ 👷 Basic array literal support using ARRAY.

SELECT ARRAY[1, 2.0::INT];

SELECT ARRAY[1::BIGINT, 2.5::INT, 3];

SELECT ARRAY['a', 'b'::TEXT, UPPER('c')];

WITH series AS (
  SELECT generate_series(1, 10)
)
SELECT ARRAY[random()::REAL, random()::REAL, random()::REAL] AS array_of_random_numbers
FROM series;

🚨 Note:
SELECT ARRAY[DATE '2020-01-01', DATE '2020-01-02'] returns java.sql.Date[] as LocalDates are not supported by PostgreSQL arrays and currently fails - see related issue #5591

TODO:

More local testing


  • CHANGELOG.md's "Unreleased" section has been updated, if applicable.

Basic support of Array Literal

The array_value_expression must be positioned, in the extension expression rule, after the double_colon expr to allow parser rule to use it inside array literals.
Basic Integration tests for array literals

Note:

In Postgresql JDBC arrays of date types cannot yet be used with LocalDate. This is an issue with the Postgresql JDBC driver and arrays

Update PostgreSqlTest.kt
IntermediateType(REAL).nullableIf(temporalExprType.javaType.isNullable)
}
plsqlTriggerVarExpression != null -> IntermediateType(TEXT)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gets the list of array elements as SqlExpr - maybe all same type or different types.
The last type in typeOrdering (numeric) will be used where mixed numeric arrays are resolved. SELECT ARRAY[1.0, 2, 3::LONG] -> numeric[].
IF any elements are NULL the result is nullable type.

}

extension_expr ::= json_object_agg_stmt | json_agg_stmt | plsql_trigger_var_expression | is_json_expression | overlaps_operator_expression | range_operator_expression | extract_temporal_expression | double_colon_cast_operator_expression | contains_operator_expression | at_time_zone_operator_expression | regex_match_operator_expression | match_operator_expression | json_function_stmt | array_agg_stmt| string_agg_stmt | json_expression | boolean_not_expression | window_function_expr {
extension_expr ::= json_object_agg_stmt | json_agg_stmt | plsql_trigger_var_expression | is_json_expression | overlaps_operator_expression | range_operator_expression | extract_temporal_expression | double_colon_cast_operator_expression | array_value_expression | contains_operator_expression | at_time_zone_operator_expression | regex_match_operator_expression | match_operator_expression | json_function_stmt | array_agg_stmt| string_agg_stmt | json_expression | boolean_not_expression | window_function_expr {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_value_expression needs to be ordered after double_colon_cast_operator_expression as the rule has higher precedence

double_colon_cast_operator ::= '::' type_name

double_colon_cast_operator_expression ::= ( {bind_expr} | {literal_expr} | {cast_expr} | {function_expr} | {column_expr} ) double_colon_cast_operator [ double_colon_cast_operator ] * {
double_colon_cast_operator_expression ::= ( array_value_expression | {bind_expr} | {literal_expr} | {cast_expr} | {function_expr} | {column_expr} ) double_colon_cast_operator [ double_colon_cast_operator ] * {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See extension_expr ordering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant