Enable bound parameters for PostgreSQL - #774
Open
josetduarte wants to merge 1 commit into
Open
Conversation
josetduarte
force-pushed
the
feat/postgres-parameters
branch
2 times, most recently
from
July 21, 2026 14:41
e75ec41 to
bbd2910
Compare
josetduarte
force-pushed
the
feat/postgres-parameters
branch
from
July 21, 2026 15:13
bbd2910 to
2f43eec
Compare
Contributor
|
@mdipierro this looks very good. @josetduarte when/if this is merged a nice follow up would be to add the json and geo functions, so postgres can be completely modernized to the new way of doing things in pydal. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant improvements to parameterized SQL compilation and execution, especially for PostgreSQL support in pyDAL. The changes ensure that the PostgreSQL backend and its compiler use the correct placeholder style (
%s), safely handle percent signs in values, and support parameterized queries across all statement types. Extensive tests are added to verify parameter binding and round-trip execution with real PostgreSQL databases.PostgreSQL Parameterization Enhancements:
PostgresCompilernow defaults to parameterized queries with the "format" placeholder style (%s), and appendsRETURNING idfor inserts when appropriate. This ensures compatibility with PostgreSQL drivers and enables safe query execution._insertmethod inPostgresis simplified to rely on the superclass implementation, leveraging the improved compiler logic.Core SQL Compiler Improvements:
\x00pydal_param_1\x00) and replaces them with%sat the end of compilation, ensuring percent signs in data do not interfere with placeholders. All statement entry points (compile_select,compile_insert,compile_update,compile_delete,compile_count) now consistently returnParamSQLobjects with parameters when appropriate. [1] [2] [3] [4] [5] [6] [7] [8]Testing and Validation:
tests/ast_params.pyare expanded to cover all statement types, edge cases with percent signs, type coercion, and round-trip execution against a live PostgreSQL database. This includes a new test class for real PostgreSQL round-trips, ensuring correctness and robustness of the parameterization logic. [1] [2]Test and Documentation Updates:
These changes collectively make parameterized SQL generation safer, more reliable, and fully compatible with PostgreSQL, while maintaining backward compatibility and improving test coverage.