Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Postgres: JSONB type override doesn't work with named parameters on Insert #4089

@martin31821

Description

@martin31821

Version

1.30.0

What happened?

I've tried to run an INSERT INTO on postgres with a JSONB column and using sqlc.arg(name)::jsonb as type.

The column is type-overridden with a custom go-struct, which also works when having $1 as parameter in the insert query. It breaks when changing $1 into sqlc.arg(name)::jsonb.

As a user, I'd expect sqlc to track the type overrides.

Relevant log output

Database schema

CREATE TABLE public.sample (
    name text not null,
    id text not null,
    settings jsonb
);

SQL queries

INSERT INTO sample (name, id, settings) VALUES (sqlc.arg(custom_name)::text, sqlc.arg(id)::text, sqlc.arg(default_settings)::jsonb) RETURNING *;

Configuration

version: "2"
sql:
- engine: "postgresql"
  schema: "sql/schema.sql"
  queries: "sql/queries.sql"
  gen:
    go:
      emit_interface: true
      emit_enum_valid_method: true
      emit_pointers_for_null_types: true
      out: "./database"
      package: "database"
      sql_package: "pgx/v5"
      overrides:
      - column: "sample.settings"
        go_type:
          type: "Settings"
          package: dto
          import: "my_pkg/dto"

Playground URL

No response

What operating system are you using?

Linux

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