Repository navigation
Replies: 1 comment 1 reply
|
This looks like an expected Psycopg 3 migration issue and, given the hook’s current driver selection, an opt-in compatibility mode seems useful to consider. PPG3 normally sends parameters separately from the SQL. PostgreSQL does not accept those parameters in several utility and DDL contexts; Psycopg documents the limitation and alternatives, including The migration path depends on which A hook-level option, defaulting to the current behavior, seems like a reasonable place to start. Implementation and tests should account for the existing cursor extra, which configures row factories under psycopg3, as well as transaction behavior, parameter types and multiple statements. There are also statement-specific alternatives. For example, Psycopg documents SQLAlchemy has its own documented Finally, SQLAlchemy’s Drafted-by: Codex (GPT-6); reviewed by @Dev-iL before posting |
Uh oh!
There was an error while loading. Please reload this page.
Background
With the migration from Psycopg 2 to Psycopg 3, PostgreSQL connections may use server-side parameter binding by default.
This is generally beneficial and works well for common DML statements such as
SELECT,INSERT,UPDATE, andDELETE.However, it may introduce compatibility issues for some existing SQL scripts, particularly parameterized DDL statements.
For example, consider a SQL script executed through
SQLExecuteQueryOperator:In some Psycopg 3 execution paths, this can fail with an error similar to:
The same SQL may have worked with Psycopg 2, where parameters were adapted on the client side.
Why this matters
Airflow is widely used for data engineering workflows, where SQL scripts often contain:
CREATE TABLE AS SELECT(CTAS)For users migrating existing DAGs to newer Airflow and PostgreSQL provider versions, this behavior may require rewriting SQL scripts even when the SQL itself is valid for PostgreSQL.
This is particularly relevant to users who use
SQLExecuteQueryOperatorto manage SQL-based ETL pipelines.Questions for the community
I'd like to hear the community's thoughts on a few questions:
PostgresHookto expose an optional client-side binding mode using Psycopg 3'sClientCursor?PostgresHook, connection extras, orSQLExecuteQueryOperator?Possible approach
One possible solution would be to allow users to opt into client-side parameter binding while keeping server-side binding as the default.
Psycopg 3 already provides
ClientCursorfor client-side binding, so Airflow might be able to expose this capability without changing the default behavior.For example, a hypothetical configuration could look like:
This is only an illustrative API proposal, not an existing Airflow parameter.
What I'd like to understand
Before proposing an implementation or opening a bug report, I'd like to understand whether this is a broader compatibility concern for Airflow users and whether the community considers an optional client-side binding mode a useful addition.
Any feedback or alternative approaches would be appreciated.
All reactions