Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using both client-side and server-side binding prevents using server-side binding #410

Closed
panthony opened this issue Jan 17, 2024 · 2 comments

Comments

@panthony
Copy link

panthony commented Jan 17, 2024

Describe the bug

Most of the SQL queries I have are dynamically generated, some parts of the query with user-provided values.

Unfortunately because of the usage of Interpolation in Python it forces me to escape every occurrences of '%' which I cannot do (or it would be way to cumbersome to even try safely).

And I can't rely on the server-side binding to work around this issue because the query will always go through the python formatting.

To Reproduce

client = Client(host='localhost')

# or even empty params for that matter
client.execute(
  "select 'Number %' as category from system.numbers WHERE number < 5 LIMIT {max:Int32}",
   params={
      'max': 10
    }
)

Expected behavior

I should be able to choose to rely on server-side binding only to avoid the escaping problem that Interpolating brings.

Versions

  • Version of package with the problem: 0.2.6
  • ClickHouse server version: 23.12.2.59
  • Python version: 3.8.16
@panthony panthony changed the title Allowing client-side and server-side binding prevent me from using server-side binding Using both client-side and server-side binding prevent me from using server-side binding Jan 17, 2024
@panthony panthony changed the title Using both client-side and server-side binding prevent me from using server-side binding Using both client-side and server-side binding prevents using server-side binding Jan 18, 2024
@xzkostyan
Copy link
Member

You can install latest master and use only server-side parameters:

from clickhouse_driver import Client

c = Client('localhost', settings={'server_side_params': True})

c.execute(
  "select 'Number %' as category from system.numbers WHERE number < 5 LIMIT {max:Int32}",
   params={
      'max': 10
    }
)

@panthony
Copy link
Author

Thanks for the quick patch, closing the issue 🙏🏻

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

No branches or pull requests

2 participants