Skip to content

Conversation

@suddendust
Copy link
Contributor

Fix Postgres cannot extract elements from a scalar error for JSON null arrays

What was breaking?

jsonb_array_elements() throws PSQLException: cannot extract elements from a scalar when encountering JSON null values in JSONB array fields. This affected both UnnestExpression queries and ArrayRelationalFilterExpression.ANY filters.

How was the bug reproduced?

Added test data with props.colors: null (JSON null, not SQL NULL) and ran queries that unnest or filter on that field.

What was the fix applied?

Replaced direct jsonb_array_elements(field) calls with:

jsonb_array_elements(CASE WHEN jsonb_typeof(field) = 'array' THEN field ELSE '[]'::jsonb END)

Testing

[X] Added integration tests

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@codecov
Copy link

codecov bot commented Jan 2, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 58.02%. Comparing base (e434dfa) to head (d29c4e4).

Files with missing lines Patch % Lines
.../v1/vistors/PostgresFromTypeExpressionVisitor.java 66.66% 0 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (e434dfa) and HEAD (d29c4e4). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (e434dfa) HEAD (d29c4e4)
integration 1 0
Additional details and impacted files
@@              Coverage Diff              @@
##               main     #265       +/-   ##
=============================================
- Coverage     80.26%   58.02%   -22.24%     
  Complexity     1337     1337               
=============================================
  Files           231      231               
  Lines          6080     6082        +2     
  Branches        545      546        +1     
=============================================
- Hits           4880     3529     -1351     
- Misses          826     2217     +1391     
+ Partials        374      336       -38     
Flag Coverage Δ
integration ?
unit 58.02% <66.66%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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