Skip to content

Issues with JSONB columns in Postgres #271

@wleev

Description

@wleev

When inserting or updating JSONB columns errors are being thrown, this seems to be due to JSON/JSONB sharing the same parameter code generator. There is no issue on reading side, only the writing side.

Error when updating a JSONB column:
Npgsql.PostgresException: 42804: column "data" is of type jsonb but expression is of type text

Changing the generated code from ( since it's a nullable column ):
command.Parameters.AddWithValue("@data", args.Data.HasValue ? args.Data.Value.GetRawText() : (object)DBNull.Value);
to
command.Parameters.AddWithValue("@data", args.Data.HasValue ? args.Data.Value : (object)DBNull.Value);
fixes the issue.

I've looked at potential code fixes. The easiest is a simple special clause in GetWriterFn for jsonb columns, but it isn't the prettiest.

Versions:

  • sqlc-gen-csharp: v0.21.0
  • sqlc: v1.29.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions