Skip to content

Enable bound parameters for PostgreSQL - #774

Merged
mdipierro merged 3 commits into
web2py:masterfrom
josetduarte:feat/postgres-parameters
Sep 14, 2026
Merged

mdipierro merged 3 commits into
web2py:masterfrom
josetduarte:feat/postgres-parameters

Conversation

@josetduarte

@josetduarte josetduarte commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Enable bound parameters by default for PostgreSQL/psycopg2 through the driver-specific PostgresPsycoCompiler, using %s placeholders. Generic PostgreSQL and JDBC compilers remain inline.

  • Preserve parameters through SELECT, COUNT, INSERT, UPDATE and DELETE compilation and execution.
  • Bind supported scalar values, IDs, references, pattern matching and CASE branches, while retaining the legacy encoding path for complex values.
  • Reuse upstream Unicode conversion for text values and patterns, and emit positional parameters in SQL order.
  • Preserve INSERT RETURNING behavior in both the compiler and legacy fallback paths, including renamed identifiers containing percent signs.
  • Include bound parameter values in generated query-cache keys without changing explicit keys or unparameterized query keys.
  • Escape literal percent signs in SQL independently from driver placeholders and parameter values.

Upstream integration

Merged upstream master without rewriting the existing PR history. Kept the upstream Unicode compatibility fix alongside the PR's ID and reference adaptation.

Regression coverage

Focused cases cover cache key compatibility and parameter isolation, composed LIKE/ILIKE/contains expressions, Unicode and NULL patterns, typed references, and INSERT behavior with compiler fallback, disabled compilation, empty rows, composite keys, renamed IDs and JDBC. The affected modules also run against an isolated PostgreSQL 16 database.

Scope

This change targets the existing PostgreSQL/psycopg2 parametrization work. New JSON/GIS operations and parameterization of additional drivers remain outside this PR.

Known upstream issue

The existing PostgreSQL recursive CTE fixture (tests.sql.TestSubselect.testCTE) uses a double-quoted space as a SQL string literal and raises UndefinedColumn. The same failure occurs on unchanged upstream dcf76747; this unrelated fixture is left outside the scope of this PR.

@josetduarte
josetduarte force-pushed the feat/postgres-parameters branch 2 times, most recently from e75ec41 to bbd2910 Compare July 21, 2026 14:41
@josetduarte
josetduarte force-pushed the feat/postgres-parameters branch from bbd2910 to 2f43eec Compare July 21, 2026 15:13
@leonelcamara

Copy link
Copy Markdown
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.

@josetduarte

Copy link
Copy Markdown
Contributor Author

@mdipierro can you check this please?

josetduarte and others added 2 commits September 14, 2026 12:16
Keep upstream Unicode conversion alongside PostgreSQL id and reference parameter adaptation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Include bound values in cache keys, preserve Unicode pattern semantics and parameter order, and retain RETURNING when INSERT falls back to the legacy compiler path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mdipierro
mdipierro merged commit 170bfe5 into web2py:master Sep 14, 2026
5 checks passed
@josetduarte
josetduarte deleted the feat/postgres-parameters branch September 15, 2026 10:22
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.

3 participants