Closed sxwebdev closed 3 years ago
Scany can handle any type that pgx can. So it's possible. As mentioned in the https://github.com/jackc/pgx/issues/809 you should define a pgx custom type or use an existing one.
After you decide what custom type you need, here are the docs on how to use a custom pgx type with scany: https://pkg.go.dev/github.com/georgysavva/scany@v0.2.5/pgxscan#hdr-Note_about_pgx_custom_types
I hope it helps!
Hey. Writing our decoder turned out to be not an easy decision. As a result, we corrected our sql request and everything works.
Earlier
array_agg(array[pr.*]) prices
Now
COALESCE(json_agg(pr.*) FILTER (WHERE pr.id IS NOT NULL), '[]') prices
Are there any disadvantages to this approach? Thanks
Hi. Sorry for the long response. From the scany perspective, it's totally fine. I don't see any problems.
OK. Thanks a lot
I ran into same problem, i want to implement the decoder for my type, but as my type is unknown and is built on runtime using joins, how would I implement decoder ? If you can give be a direction, it would be great .
@pragyanaryal Hi and thanks for asking. I need more information about your case, but at the first glance, it seems unrelated to this thread. Could you please create a new issue and provide more details such as: struct definition, SQL query and how you call the scany library. Thanks!
Hey. I have a problem that I described earlier at this link.
I updated my code a bit and it turns out the following.
The question is as follows. How to use array_agg? I am unable to decode the array
[]Price
If possible, show with this example how to decode an array from postgres
Thanks