Skip to content

feat(analysis): treat subscripted array columns as expressions - #77

Merged
omer-cengel merged 1 commit into
masterfrom
feature/subscripted-array-columns-as-expressions
Oct 11, 2026
Merged

omer-cengel merged 1 commit into
masterfrom
feature/subscripted-array-columns-as-expressions

Conversation

@omer-cengel

Copy link
Copy Markdown
Member

Summary

A column reference written with an array subscript or slice, such as labels[1], labels[1:2], or t.labels[1], was analyzed as the whole array column. A projection of it generated a List component and a placeholder compared with it bound a List, both of which compiled but failed against PostgreSQL. Such a reference is now analyzed as an expression, so its type must be stated with a cast.

Changes

  • A subscripted or sliced projection is rejected as a computed projection unless a cast states its type: labels[1]::text AS first is a String component, and labels[1:2]::varchar[] AS pair is a list component.
  • A subscripted or sliced RETURNING item is rejected as a computed returned item, with or without an alias.
  • An uncast placeholder beside a subscripted or sliced reference is no longer typed from the array column. It is reported with the untyped-placeholder diagnostic in comparisons of either order, IN, LIKE, BETWEEN, = ANY, join ON conditions, write WHERE clauses, DO UPDATE ... WHERE, SET assignments, and INSERT values.
  • A cast placeholder beside a subscripted reference is typed by its cast and named after itself: an indexed one is param<N>, so labels[1] = $1::text binds param1.
  • A subscripted SET or INSERT target must still name an existing column, and the subscript reaches the database as written.
  • Query and PostgreSQL array documentation describe the rule, with analyzer tests per location and a PostgreSQL test reading and filtering by one element.

Scope and non-goals

  • A subscript is not typed as its element type; a cast states it.
  • Unsubscripted column references behave exactly as before, and placeholder binding order stays textual.
  • Null tests, join conditions, EXCLUDED values, and conflict targets keep their existing column checks.
  • Placeholders inside a subscript, parenthesized or multi-level subscripts such as (labels)[1] and labels[1][2], and open slices are not changed.

@omer-cengel
omer-cengel merged commit edc5a0a into master Oct 11, 2026
7 checks passed
@omer-cengel
omer-cengel deleted the feature/subscripted-array-columns-as-expressions branch October 11, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant