Skip to content

Using RowToStructByName does not seem to work ByName with embedded structs #1914

Answered by svennis94
svennis94 asked this question in Q&A
Discussion options

You must be logged in to vote

So after some tinkering I have build a PoC, this is by no means perfect. But it works without any changes to PGx itself. We have decided to go a different route and we will defined the columns in the correct order. But I'll leave the PoC here in case anybody else is looking to retrieve the same result.

There was one small issue that I ran into and that is that the pgtype.ptrStructWrapper has the exportedFields field, sadly that field is not exported. If it was exported then I could use the index from the reflect.Value based on the column and field name. For the PoC I generated my own mapping (column name -> field index in struct, as a map[string]int). Other than that I have used the default

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@svennis94
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by svennis94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants