Skip to content

fix: the length of an empty array is zero - #255

Merged
zachdaniel merged 1 commit into
ash-project:mainfrom
matt-beanland:fix/array-length-of-empty
Aug 21, 2026
Merged

fix: the length of an empty array is zero#255
zachdaniel merged 1 commit into
ash-project:mainfrom
matt-beanland:fix/array-length-of-empty

Conversation

@matt-beanland

Copy link
Copy Markdown
Contributor

Contributor checklist

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

Fixes ash-project/ash_postgres#834

The list is rendered twice, since cardinality alone regresses nested arrays, by counting across all dimensions. Similarly coalesce(.., 0) turns a nil array into 0.

Tests will be in an ash_postgres PR, which will require ash_sql to release to go green.

Comment thread lib/expr.ex
embedded?: pred_embedded?,
arguments: [
raw: "array_length((",
raw: "coalesce(array_length((",

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.

Rendering the list twice is not great 😓 Is there really no other way to go about this?

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.

Actually, I think it's fine. If its a literal list then the value would be expanded by our expression builder at runtime.

@zachdaniel
zachdaniel merged commit 26427a8 into ash-project:main Aug 21, 2026
26 checks passed
@zachdaniel

Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

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.

length of empty array is nil

2 participants