Skip to content

Fix empty arrays decoding as List<Object?> instead of a list of their element type - #472

Merged
isoos merged 2 commits into
isoos:masterfrom
xvrh:xha/empty-array-type
Oct 4, 2026
Merged

isoos merged 2 commits into
isoos:masterfrom
xvrh:xha/empty-array-type

Conversation

@xvrh

@xvrh xvrh commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Since 3.5.18 (the multi-dimensional array change), an empty array loses its element type when it is decoded:

Query 3.5.17 3.5.18 With this PR
SELECT '{a}'::text[] List<String> List<String> List<String>
SELECT '{}'::text[] List<String?> List<Object?> List<String>

So code that casts an array column, such as row[0] as List<String>, works for non-empty arrays and throws for empty ones: type 'List<Object?>' is not a subtype of type 'List<String>'.

An empty array now decodes as a list of its element type, as a non-empty one does. List<String> satisfies both as List<String> and as List<String?>.

Tests: the existing "Decodes an empty array" test compared the result with <int>[], and list equality ignores the element type. New tests check the decoded type of empty int4, int8, text, varchar, bool, float8 and uuid arrays. They fail before this change and pass after. The full suite passes.

xvrh added 2 commits October 2, 2026 12:05
…ir element type.

Since 3.5.18 an empty array, `'{}'::text[]` say, decoded as an empty
`List<Object?>` while a non-empty one decodes as `List<String>`, so a
cast like `row[0] as List<String>` threw for empty arrays only. An
empty array is a list of its element type again.
@isoos
isoos merged commit de86a2a into isoos:master Oct 4, 2026
1 check 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