Skip to content

Inserting null string into Nullable(JSON) cause error #1707

@topofstack

Description

@topofstack

Observed

  1. Define a ClickHouse table containing a Nullable(JSON) column
  2. Insert a nil string into this column

Received error is:

code: 117, message: Cannot parse JSON object here:

Expected behaviour

A null value should be inserted into the table

Code example

func TestNullableJSON(t *testing.T) {
	ctx := context.Background()

	conn, err := clickhouse.Open(&clickhouse.Options{
		Addr: []string{"127.0.0.1:9000"},
		Auth: clickhouse.Auth{
			Database: "default",
			Username: "default",
		},
	})
	require.NoError(t, err, "open clickhouse")

	_ = conn.Exec(ctx, `DROP TABLE IF EXISTS t`)
	err = conn.Exec(ctx, `
		CREATE TABLE t
		(
			data Nullable(JSON)
		)
		ENGINE = Memory
	`)
	require.NoError(t, err, "create table")

	batch, err := conn.PrepareBatch(ctx, `INSERT INTO t (data) VALUES (?)`)
	require.NoError(t, err, "prepare batch")

	var s *string
	require.NoError(t, batch.Append(s))
	require.NoError(t, batch.Send(), "batch send")
}

Details

As it appears in similar issue #1638, only Batch behavior is affected.

Environment

  • clickhouse-go version: v2.40.3
  • Interface: ClickHouse API
  • Go version: go1.24.10
  • Operating system: OSX
  • ClickHouse version: 25.8.5.17

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