Skip to content

Conversation

@pravic
Copy link
Contributor

@pravic pravic commented Sep 18, 2024

Summary

Allow to print the current SQL query, whether it's bound or not. Useful for logging and diagnostics.

Note: I chose Debug over Display because the latter is too implicit and somebody might accidentally pass a query into a string.

Albeit, something like fn Query::into_string(self) -> String can be useful on its own - as a poor man's query builder:

let q = client.query("SELECT id from system.users WHERE name = ?");
let q = q.bind("default");

// store the query string for later 
let query_string = q.into_string(); // returns `q.sql.finish()` inernally

// then execute it:
client.query(&query_string).fetch();

closes #146

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided so that we can include it in CHANGELOG later
  • For significant changes, documentation in README and https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials
  • conflicts with Query parser: encode ?? as ? #154, this PR needs to be rebased on top of that

Allow to print the current SQL query,
whether it's bound or not.

Useful for logging and diagnostics.
Allow to print the current SQL query,
whether it's bound or not.

Useful for logging and diagnostics.
@slvrtrn slvrtrn requested review from loyd and serprex September 19, 2024 09:20
serprex
serprex previously approved these changes Sep 19, 2024
Copy link
Collaborator

@loyd loyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only misleading Debug impl, all other changes are fine

@CLAassistant
Copy link

CLAassistant commented Sep 20, 2024

CLA assistant check
All committers have signed the CLA.

`Debug` for `Query` isn't a good idea.
@loyd loyd merged commit 75ce343 into ClickHouse:main Sep 24, 2024
6 checks passed
@loyd
Copy link
Collaborator

loyd commented Sep 24, 2024

@pravic, thanks for your contribution!

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.

Implement std::fmt::Display for Query

4 participants