Skip to content

Instantly share code, notes, and snippets.

@kavirajk
Created October 3, 2025 09:53
Show Gist options
  • Save kavirajk/549bb4ca4c757040d1c994ea2f845ef8 to your computer and use it in GitHub Desktop.
Save kavirajk/549bb4ca4c757040d1c994ea2f845ef8 to your computer and use it in GitHub Desktop.
withstdAsync_driverConn.go
func TestWithStdAsync(t *testing.T) {
conn, err := clickhouse.Open(&clickhouse.Options{
Addr: []string{"localhost:9000"},
Protocol: clickhouse.Native,
})
require.NoError(t, err)
ctx := context.Background()
queryID := fmt.Sprintf("%d", time.Now().Unix())
// queryID := "async-with-opendb"
ctx = clickhouse.Context(ctx, clickhouse.WithStdAsync(true), clickhouse.WithQueryID(queryID))
err = conn.Exec(ctx, `DROP TABLE IF EXISTS example`)
require.NoError(t, err)
const ddl = `
CREATE TABLE example (
Col1 UInt64
, Col2 String
, Col3 Array(UInt8)
, Col4 DateTime
) ENGINE = Memory
`
require.NoError(t, conn.Exec(ctx, ddl))
for i := 0; i < 100; i++ {
err := conn.Exec(ctx, `INSERT INTO example VALUES (?, ?, ?, now())`, i, "Golang", []uint8{1, 2, 4})
require.NoError(t, err)
}
fmt.Println("QueryID", queryID)
}
@kavirajk
Copy link
Author

kavirajk commented Oct 3, 2025

This one doesnt' respect the async settings passed in via context.

d280839474d7 :) select query, Settings from system.query_log where query_id='1759484794' ORDER BY event_time desc LIMIT 10;

SELECT
    query,
    Settings
FROM system.query_log
WHERE query_id = '1759484794'
ORDER BY event_time DESC
LIMIT 10

Query id: 03818d75-3d8e-4c99-8900-b2f8371bae53

    ┌─query───────────────────────┬─Settings─┐
 1. │ INSERT INTO example VALUES  │ {}       │
 2. │ INSERT INTO example VALUES  │ {}       │
 3. │ INSERT INTO example VALUES  │ {}       │
 4. │ INSERT INTO example VALUES  │ {}       │
 5. │ INSERT INTO example VALUES  │ {}       │
 6. │ INSERT INTO example VALUES  │ {}       │
 7. │ INSERT INTO example VALUES  │ {}       │
 8. │ INSERT INTO example VALUES  │ {}       │
 9. │ INSERT INTO example VALUES  │ {}       │
10. │ INSERT INTO example VALUES  │ {}       │
    └─────────────────────────────┴──────────┘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment