Created
November 11, 2025 07:37
-
-
Save kavirajk/98517052add7aaadc87612eccb57a9ec to your computer and use it in GitHub Desktop.
Query params ch-go array
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
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "github.com/ClickHouse/ch-go" | |
| "github.com/ClickHouse/ch-go/proto" | |
| ) | |
| func main() { | |
| ctx := context.Background() | |
| c, err := ch.Dial(ctx, ch.Options{Address: "localhost:9000"}) | |
| if err != nil { | |
| panic(err) | |
| } | |
| var ( | |
| numbers int | |
| data proto.ColUInt64 | |
| ) | |
| params := ch.Parameters(map[string]any{ | |
| "array": "['a', 'b', 'c', 'heltlo', 'testing']", | |
| "column": "number", | |
| "database": "system", | |
| "table": "numbers", | |
| }) | |
| if err := c.Do(ctx, ch.Query{ | |
| // Body: "SELECT number FROM system.numbers LIMIT 500000000", | |
| Body: "SELECT {column:Identifier} v, {array:Array(String)} a FROM {database:Identifier}.{table:Identifier} LIMIT 1 OFFSET 100", | |
| Result: proto.Results{ | |
| {Name: "number", Data: &data}, | |
| }, | |
| // OnResult will be called on next received data block. | |
| OnResult: func(ctx context.Context, b proto.Block) error { | |
| numbers += len(data) | |
| return nil | |
| }, | |
| Parameters: params, | |
| }); err != nil { | |
| panic(err) | |
| } | |
| fmt.Println("numbers:", numbers) | |
| } |
Author
kavirajk
commented
Nov 11, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment