Skip to content

Fix encoding/decoding of arrays of domains defined over arrays#778

Merged
greg-rychlewski merged 1 commit into
elixir-ecto:masterfrom
greg-rychlewski:array_of_domain_array
Jul 6, 2026
Merged

Fix encoding/decoding of arrays of domains defined over arrays#778
greg-rychlewski merged 1 commit into
elixir-ecto:masterfrom
greg-rychlewski:array_of_domain_array

Conversation

@greg-rychlewski

Copy link
Copy Markdown
Member

Sorry for throwing another weird one your way about domains. This comment here basically explains it

# A nested array is normally handled by recursing through the dimensions
  # until you hit the base element. However, there is a special case
  # where a parameter may look like a nested array but we cannot treat it
  # this way. An array whose element type is a domain that is defined
  # over an array will look like a nested array from Elixir, but the
  # Postgres protocol must treat it as a single dimensional array over
  # the domain type

Comment on lines +120 to +121
def recurse_nested_arrays({__MODULE__, _, _}), do: false
def recurse_nested_arrays(_), do: true

@greg-rychlewski greg-rychlewski Jul 5, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The reason why this check works is because no matter how many dimensions the array is over a non-domain type, the sub type is still considered the base type. For example [[[[[int]]]]] will still just have a sub type of int. This is enforced by Postgres and not just a quirk of how we handle types.

But [domain_over_array] will have a sub type of array. This is also enforced by postgres or else the protocol rejects it. i.e. postgres doesn't see base_type[][] the same as domain_over_array_of_base_type[].

@greg-rychlewski greg-rychlewski merged commit 1e41dd1 into elixir-ecto:master Jul 6, 2026
25 of 26 checks passed
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