clickhouse-go icon indicating copy to clipboard operation
clickhouse-go copied to clipboard

std: support prepared SELECT/DDL via database/sql; add examples/tests

Open theboringhumane opened this issue 4 months ago • 3 comments

Implement driver-side prepared statements for non-INSERT queries in the database/sql compatibility layer.

Changes:

  • Introduce stdStmt and wire it into PrepareContext for non-INSERT statements

  • Implement StmtQueryContext/StmtExecContext using underlying connection

  • Preserve INSERT behavior via stdBatch (Exec-only)

  • Add example examples/std/prepared.go and run it in examples suite

  • Add tests: prepared select, USE + prepared select, and merged funds temp test

  • Remove temporary test file; fix minor linter warning in clickhouse_std.go

Rationale:

  • Restores database/sql compatibility for prepared read queries (e.g., Stmt.QueryContext) while keeping batch INSERT semantics

Summary

Checklist

Delete items not relevant to your PR:

  • [x] Unit and integration tests covering the common scenarios were added
  • [x] A human-readable description of the changes was provided to include in CHANGELOG
  • [ ] For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

theboringhumane avatar Sep 17 '25 05:09 theboringhumane

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 17 '25 05:09 CLAassistant

@theboringhumane thanks for the contribution. can you take care of the failing test cases?

code: 62, message: Syntax error: failed at position 58 (end of query) (line 3, col 5): . Expected one of: token, Dot, OpeningRoundBracket, FROM INFILE, SETTINGS, VALUES, FORMAT, SELECT, WITH

kavirajk avatar Sep 19 '25 11:09 kavirajk

@theboringhumane thanks for the contribution. can you take care of the failing test cases?

code: 62, message: Syntax error: failed at position 58 (end of query) (line 3, col 5): . Expected one of: token, Dot, OpeningRoundBracket, FROM INFILE, SETTINGS, VALUES, FORMAT, SELECT, WITH

I'll take care of that. No sweat.

theboringhumane avatar Sep 19 '25 11:09 theboringhumane