[Question] How can I Insert an array of a custom postgres type using driver.Value
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
Hello,
I am trying to get the following to work:
```go
type StickerState struct {
ID int
Wear int
Slot int
}
type StickerStates []StickerState
func (s StickerStates) Value() (driver.Value, error) {
if len(s) == 0 {
return "{}", nil
}
var rows []string
for _, entry := range s {
row := fmt.Sprintf("(%d, %d, %d)", entry.ID, entry.Wear, entry.Slot)
rows = append(rows, row)
}
return fmt.Sprintf("(%s)", strings.Join(rows, ",")), nil
}
type MarketListing struct {
...
Stickers StickerStates
...
}
```
When passing my go slice of type StickerState i get the following error while inserting:
`ERROR: malformed array literal: "((0, 100, 0))" (SQLSTATE 22P02)`
Contributor guide
Research direction
Start with the StickerStates.Value method and the failing insert described in the issue; review how pgx handles driver.Valuer values for PostgreSQL custom types and arrays. Reproduce the minimal insertion and verify that the resulting value is accepted without the malformed array literal error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100