Skip to content

Comments

Support setting array columns to empty array instead of setting those to null#762

Merged
BenoitRanque merged 2 commits intomainfrom
support-set-array-to-null
May 12, 2025
Merged

Support setting array columns to empty array instead of setting those to null#762
BenoitRanque merged 2 commits intomainfrom
support-set-array-to-null

Conversation

@BenoitRanque
Copy link
Contributor

What

Attempting to set an array column to [] would instead set the column to NULL.
This happened because we process the incoming values using array_agg, which returns null if aggregating over no rows.

How

We wrap the array aggregation in COALESCE, with a default value of an empty array cast to the right type.

The new behavior when updating an array column is now

  • setting to an array with elements works as before
  • setting to null works as before
  • setting to an empty array works as expected, wheras before it would be set to null.

The PR also adds snapshot tests for all 3 cases. The snapshotted SQL has been tested and verified to behave as intended.

Some other snapshots are also updated due to the change in generated SQL.
It seems we use the functions in values.rs every time we have some kind of json input.

This is not what I set out to fix, and there could be issues if we're relying on the null behavior here, but I don't think we are.

@BenoitRanque BenoitRanque requested a review from a team as a code owner May 9, 2025 04:35
@BenoitRanque BenoitRanque enabled auto-merge May 12, 2025 13:54
@BenoitRanque BenoitRanque added this pull request to the merge queue May 12, 2025
Merged via the queue into main with commit 32aad6b May 12, 2025
27 of 29 checks passed
@BenoitRanque BenoitRanque deleted the support-set-array-to-null branch May 12, 2025 14: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.

2 participants