Skip to content

Comments

avoid excessive array wrapping#1162

Closed
toqueteos wants to merge 1 commit intolib:masterfrom
toqueteos:avoid-array-excessive-wrapping
Closed

avoid excessive array wrapping#1162
toqueteos wants to merge 1 commit intolib:masterfrom
toqueteos:avoid-array-excessive-wrapping

Conversation

@toqueteos
Copy link

@toqueteos toqueteos commented Jun 27, 2024

pq.Array shouldn't wrap values that are already an optimal pq Array type.

x := []string{"a", "b", "c"}
pq.Array(x) // is (*pq.StringArray)
pq.Array(pq.Array(x)) // is (pq.GenericArray)

Repro:

package main

import (
	"fmt"

	"github.com/lib/pq"
)

func p(x any) {
	fmt.Printf("%v (%T)\n", x, x)
}

func main() {
	x := []string{"a", "b", "c"}

	p(x)
	p(pq.Array(x))
	p(pq.Array(pq.Array(x)))
}

@arp242 arp242 added needs-test Needs a test before it can be merged enhancement labels Dec 31, 2025
@arp242
Copy link
Collaborator

arp242 commented Jan 13, 2026

I would expect pq.Array(pq.Array(pq.Int32Array{1,2,3})) to be a multi-dimensional array like {{1,2,3}}. That doesn't really work (yet), but I wouldn't really expect it to be "silently" flattened to {1,2,3}.

In general it's unclear to me what problem or use case this solves?

@arp242 arp242 added the needs-feedback Requires feedback to be actionable label Jan 13, 2026
@toqueteos
Copy link
Author

The reality is that multi-dimensional arrays are very underutilized in the real world and while correct that approach leads to serialization issues for the most common scenario.

Which is how I found our DIY orm-like layer was sometimes wrapping already-wrapped arrays.

No matter if this change is accepted or not, the docs should be updated to reflect the decision to support multi-dimensional arrays or to flatten.

@arp242
Copy link
Collaborator

arp242 commented Jan 14, 2026

The reality is that multi-dimensional arrays are very underutilized in the real world and while correct that approach leads to serialization issues for the most common scenario.

Well maybe, but it seems rather inappropriate to start making opinionated decisions about that in a PostgreSQL driver – that should support whatever PostgreSQL supports, no?

@arp242 arp242 closed this Jan 19, 2026
@toqueteos toqueteos deleted the avoid-array-excessive-wrapping branch January 19, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement needs-feedback Requires feedback to be actionable needs-test Needs a test before it can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants