Encode Plan for Nested Arrays of Custom Type #2423
Answered
by
jackc
carmichaeljr
asked this question in
Q&A
|
I have a struct like the following: type PhysicsData struct {
Time [][]types.Second
// ... many other fields
}
type Second float64If I have the following query defined in a file that sqlc parses: -- name: CreatePhysicsData :one
INSERT INTO providentia.physics_data(time, ... many other fields)
VALUES ($1, ... many other fields) RETURNING id;When I run the above sql query with the struct shown below I get no error. PhysicsData{
Time: [][]types.Second{[]types.Second{1,2,3}},
}However, If I try to run the above sql query with any of the following structs I get the error shown below. PhysicsData{
Time: [][]types.Second{[]types.Second{1,2,3}, nil},
}
PhysicsData{
Time: [][]types.Second{[]types.Second{1,2,3}, []types.Second{}},
}
PhysicsData{
Time: [][]types.Second{[]types.Second{1,2,3}, []types.Second{0}},
}I have found several discussions about registering custom types but (1) why is that not necessary when inserting the first struct and (2) if I do really need to register types how can I register a type from a separate package? |
Answered by
jackc
Nov 8, 2025
Replies: 1 comment 3 replies
|
It's hard to say without being able to see the actual queries. If you can reduce it to a self-contained example that might help. |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are multiple issues here.
First, I was able to reduce the scope of your example significantly. See below for the code. In particular, custom types have nothing to do with the issue you are experiencing. The same behavior occurs when using
float64directly.Second, once example was reduced, the problem became clearer. You are trying to do things that PostgreSQL doesn't support. See what happens if you try to do this in psql.