sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
12.27k stars 778 forks source link

NULL JSON field fails to Scan into json.RawMessage #3373

Open Jille opened 4 months ago

Jille commented 4 months ago

Version

1.26.0

What happened?

I have a MariaDB table with a nullable JSON column but selecting it when the value is NULL fails to Scan() it into the field.

I'm using the github.com/go-sql-driver/mysql driver.

Relevant log output

sql: Scan error on column index 1, name "my_json_column": unsupported Scan, storing driver.Value type <nil> into type *json.RawMessage

### Database schema

```sql
CREATE TABLE authors (
  id   INT PRIMARY KEY,
  bio  JSON
);

SQL queries

-- name: GetAuthor :one
SELECT * FROM authors WHERE id = ?;

Configuration

No response

Playground URL

https://play.sqlc.dev/p/8e1085762b38b90fb51da2bdac5fe4d2b37d6b89cfae5562063e295d3a829a18

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

jarri-abidi commented 2 weeks ago

any plans to fix this @kyleconroy? if you can suggest how to do it, maybe i can try