Skip to content

Assign types to json aggregations #2788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
boyswan opened this issue Sep 28, 2023 · 3 comments
Open

Assign types to json aggregations #2788

boyswan opened this issue Sep 28, 2023 · 3 comments

Comments

@boyswan
Copy link

boyswan commented Sep 28, 2023

What do you want to change?

AFAIK sqlc cannot assign types to json aggregations.

For example:

select 
  ...
  json_build_object(
    'id', s.id,
    'description', s.description
  ) as Show
from ...

Show will be exported as []bytes. I am able to get around this by skipping sqlc and using pgx:

v, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[types.PersonWithShow])

However seeing that sqlc can assign types to jsonb at a column level via overrides, I feel it would be very useful to be able to assign types to json at a query level.

What I would like to be able to do is:

  json_build_object(
    'id', s.id,
    'description', s.description
  )::Show as Show

I went down a rabbit hole trying to add custom pg types and setting db_type as an attempt for this to work in sqlc's current state, but gave up as I wasn't convinced this was the right direction.

Is this something that is possible in sqlc?

What database engines need to be changed?

PostgreSQL

What programming language backends need to be changed?

Go

@boyswan boyswan added enhancement New feature or request triage New issues that hasn't been reviewed labels Sep 28, 2023
@kyleconroy
Copy link
Collaborator

Tracking JSON unmarshaling of custom structs here: #2761 and composite type support here #2760.

@kyleconroy kyleconroy added 📚 postgresql 🔧 golang pgx/v5 and removed triage New issues that hasn't been reviewed labels Oct 2, 2023
@kyleconroy kyleconroy changed the title Assign types to json aggregations (pgx) Assign types to json aggregations Oct 2, 2023
@hariangr
Copy link

hariangr commented Dec 6, 2023

Any update on this?

@asineth0
Copy link

I would really like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants