Created
January 8, 2026 11:12
-
-
Save kavirajk/25dd76787c6790af9265a09310cffbe0 to your computer and use it in GitHub Desktop.
json_error.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func main() { | |
| conn, err := clickhouse.Open(&clickhouse.Options{ | |
| Addr: []string{ | |
| "127.0.0.1:9000", | |
| }, | |
| }) | |
| create := ` | |
| CREATE OR REPLACE TABLE test_json ( | |
| id Int, | |
| data String | |
| ) ENGINE = ReplacingMergeTree | |
| ORDER BY (id); | |
| ` | |
| ctx := context.Background() | |
| err = conn.Exec(ctx, create) | |
| if err != nil { | |
| panic(err) | |
| } | |
| // Omitting error checks | |
| chCtx := clickhouse.Context(ctx, clickhouse.WithParameters(clickhouse.Parameters{ | |
| "id": "1", | |
| "data": `{"foo": "bar", "nested_data": "{\"key\": \"value\", \"count\": 10}"}`, | |
| })) | |
| err = conn.Exec(chCtx, "INSERT INTO default.test_json VALUES ({id:Int}, {data:String})") | |
| if err != nil { | |
| panic(err) | |
| } | |
| // Omitting error checks | |
| batch, _ := conn.PrepareBatch(ctx, "INSERT INTO default.test_json") | |
| _ = batch.Append( | |
| 1, `{"foo": "bar", "nested_data": "{\"key\": \"value\", \"count\": 10}"}`, | |
| ) | |
| if err := batch.Send(); err != nil { | |
| panic(err) | |
| } | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And I see the data are ingested in both cases (query params and batch insert).