Skip to content

nullable jsonb failed to specify its struct #4030

@bhscer

Description

@bhscer

Version

1.29.0

What happened?

The doc https://docs.sqlc.dev/en/stable/reference/datatypes.html#json says that we can specify the struct to a jsonb, but I tried to make a easy demo of doc's code and failed.

The generated model is

type Book struct {
	ID   int32
	Data types.BookData
}

but the doc says that will be

type Book struct {
    Data *dto.BookData
}

This problem also happens in EditBookParams, I have provide the playground url: https://play.sqlc.dev/p/b1e8f0509a8d5c4e13f18db4b738040590eb1debc7439b4169314568d72e7742

Relevant log output

Database schema

CREATE TABLE books (
    id SERIAL PRIMARY KEY,
    data jsonb
);

SQL queries

-- name: GetBookById :one
SELECT * FROM books
WHERE id = @id LIMIT 1;

Configuration

version: "2"

sql:
  - engine: "postgresql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "database"
        out: "database"
        sql_package: pgx/v5

        emit_empty_slices: true
        emit_pointers_for_null_types: true

        overrides:
          - column: "books.data"
            go_type:
              import: "sqlc-test/types"
              package: "types"
              type: "BookData"

Playground URL

https://play.sqlc.dev/p/b1e8f0509a8d5c4e13f18db4b738040590eb1debc7439b4169314568d72e7742

What operating system are you using?

Windows

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions