Skip to content

Feature/named parameter support#795

Open
bgunebakan wants to merge 3 commits intocrate:mainfrom
bgunebakan:feature/named-parameter-support
Open

Feature/named parameter support#795
bgunebakan wants to merge 3 commits intocrate:mainfrom
bgunebakan:feature/named-parameter-support

Conversation

@bgunebakan
Copy link

@bgunebakan bgunebakan commented Mar 23, 2026

Summary of the changes / Why this is an improvement

Adds client-side named parameter support (pyformat paramstyle) to the CrateDB Python client, addressing the request in #774.

Previously, cursor.execute() only accepted positional ? placeholders. Users with complex SQL had to maintain a positional list that was error-prone and hard to read.

With this change, a dict can be passed as the parameters argument using %(name)s placeholders:

cursor.execute(
    "SELECT * FROM t WHERE city = %(city)s AND kiez = %(kiez)s",
    {"city": "Berlin", "kiez": "Kreuzberg"},
)

The same parameter name may appear multiple times in the query, each occurrence is resolved independently:

cursor.execute(
    "SELECT * FROM t WHERE state = %(q)s OR city = %(q)s",
    {"q": "Berlin"},
)

Positional ? queries continue to work unchanged, no breaking change.

Known limitation

Supporting named params in bulk operations are not supported because it requires a different approach from execute(). We need to extract the ordered parameter name list from the SQL. Excluded from this PR to keep this PR focused on the core execute() case.

Checklist

@amotl amotl requested review from mfussenegger and seut March 24, 2026 23:10
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.

Parameter binding failure with string containing "{{value}}" and lack of named parameter support

2 participants