Skip to content

docs: commit the batch in the database/sql Sessions example and restore its full example - #2187

Open
VanshajPoonia wants to merge 2 commits into
ClickHouse:mainfrom
VanshajPoonia:docs/2185-sessions-commit
Open

VanshajPoonia wants to merge 2 commits into
ClickHouse:mainfrom
VanshajPoonia:docs/2185-sessions-commit

Conversation

@VanshajPoonia

@VanshajPoonia VanshajPoonia commented Nov 30, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2185.

The "Sessions" snippet in docs/database-sql-api.mdx adds 10 rows to a batch from conn.Begin() and then reads the table. It does not call Commit, so the driver never sends the batch and the SELECT returns no rows. The snippet now calls scope.Commit() before the SELECT, as the "Batch insert" section of the same page says.

The "Full Example" link under the snippet points to examples/std/session.go, which #1258 removed. This PR restores that file with the commit and adds TestStdSession back to examples/std/main_test.go. The example returns an error if it does not read the 10 rows back, so the test fails if the snippet breaks again. #1258 gives no reason for the removal. If you prefer to keep the example out, I can remove the link instead.

Checklist

  • Unit and integration tests covering the common scenarios were added

go test ./examples/std/ -run TestStdSession -count=20 passes 20 of 20 on ClickHouse 26.11.5.8 (latest), and each run prints row: col1=0 to row: col1=9. Without the Commit, the test fails with expected 10 rows, got 0. go test ./examples/std/ passes.


Note

Low Risk
Documentation and example/test-only changes; no driver or runtime behavior is modified.

Overview
Fixes the Sessions snippet in docs/database-sql-api.mdx by calling scope.Commit() after the batched INSERT and before SELECT, matching the Batch insert guidance so HTTP session batch data is actually sent.

Restores examples/std/session.go (linked from the docs) with the same flow, explicit commit, and an assertion that all 10 rows are read back. Adds TestStdSession in examples/std/main_test.go so the example stays correct.

Reviewed by Cursor Bugbot for commit e4e1191. Bugbot is set up for automated code reviews on this repo. Configure here.

The snippet appended 10 rows to a batch and read the table without a Commit, so the batch was never sent and the SELECT returned no rows.

Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
The Sessions docs link to examples/std/session.go, which was removed in ClickHouse#1258. The example commits its batch and returns an error if it does not read the 10 rows back, so TestStdSession fails if the snippet breaks again.

Signed-off-by: Vanshaj Poonia <vanshajtheunique@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: database/sql Sessions example never commits its batch, and its "Full Example" link is a 404

1 participant