Skip to content

Fix array positions rendering as object keys, and subscripts served from the statement cache - #314

Merged
bgunebakan merged 8 commits into
mainfrom
bilal/309-reading-an-array-element-by-position-fails
Oct 1, 2026
Merged

bgunebakan merged 8 commits into
mainfrom
bilal/309-reading-an-array-element-by-position-fails

Conversation

@bgunebakan

@bgunebakan bgunebakan commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary of the changes / Why this is an improvement

CrateDB rejects a bare bind parameter as a position or key (arr[?] fails with Parameter substitution is not supported in subscript index), but accepts one inside an expression (arr[id + ?], arr[abs(?)], also as an UPDATE target).

  • An integer as a position, a string as a quoted, escaped key. When the statement is compiled for the cache, the literal is filled in on each execution (literal_execute).
  • An expression that renders as a bare parameter, like type_coerce(literal(2), Integer), is unwrapped and treated as a plain value.
  • Slices render as start:stop, with bind parameters as bounds. A step raises CompileError.
  • An integer on a top-level object keeps meaning the key (obj[1] → obj['1'], as on main), because CrateDB never accepts a position there.
  • A subscript that is neither an integer nor a string raises CompileError.

Behavior changes

  • ObjectArray and sa.JSON subscripts no longer return a cached statement's results.
  • bool, float and None subscripts raise CompileError. Before, they rendered as keys such as obj['True'].
  • A cached statement with a literal subscript, like WHERE js['x'] = :v, can't run with executemany(): SQLAlchemy doesn't support literal_execute there, the same restriction it has for expanding IN.

References for implementation

Out of scope

  • tests/query_caching.py renamed to tests/query_caching_test.py to align with naming on all tests.

Checklist

@bgunebakan bgunebakan self-assigned this Sep 25, 2026
@bgunebakan bgunebakan linked an issue Sep 25, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 5cab6b22-87f7-4534-b690-489315dfef23

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@bgunebakan bgunebakan changed the title FIX Reading an array element by position fails Fix array positions rendering as object keys, and subscripts served from the statement cache Sep 25, 2026
Comment thread CHANGES.md Outdated
Comment on lines +21 to +26
- Compiler: Fixed array indexes rendering as object keys, as in `arr['1']`.
Added support for array slices, and for columns and expressions as indexes
- Fixed the statement cache returning results for another key on
`ObjectArray` and `JSON` subscripts and escaped quotes in object keys.
- Statements with a literal subscript, as in `js['x']` run with
`execution_options(compiled_cache=None)`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR looks ace, but I think you just need to signal more changes:

Suggested change
- Compiler: Fixed array indexes rendering as object keys, as in `arr['1']`.
Added support for array slices, and for columns and expressions as indexes
- Fixed the statement cache returning results for another key on
`ObjectArray` and `JSON` subscripts and escaped quotes in object keys.
- Statements with a literal subscript, as in `js['x']` run with
`execution_options(compiled_cache=None)`
- Compiler: Fixed array indexes rendering as object keys, as in `arr['1']`.
Added support for array slices, and for columns and expressions as indexes
- Compiler: Fixed cached statements on `sa.JSON` and `ObjectArray` columns
reusing the subscript of an earlier statement, which returned values of
another key. Fixed object keys containing a quote
- Compiler: A statement with a literal subscript can't run with `executemany()`
on a cached engine. For that, use `execution_options(compiled_cache=None)`
- Compiler: An integer subscript on a nested object renders as an array
position. Write the key as a string, as in `obj['n']['1']`
- Compiler: `bool`, `float` and `None` subscripts raise `CompileError`

@bgunebakan
bgunebakan merged commit df4a114 into main Oct 1, 2026
25 checks passed
@bgunebakan
bgunebakan deleted the bilal/309-reading-an-array-element-by-position-fails branch October 1, 2026 11:11
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.

Reading an array element by position fails

2 participants