its-amann commented on code in PR #76962:
URL: https://github.com/apache/airflow/pull/76962#discussion_r4546539110
##########
providers/postgres/src/airflow/providers/postgres/dialects/postgres.py:
##########
@@ -51,7 +51,7 @@ def get_primary_keys(self, table: str, schema: str | None =
None) -> list[str] |
and kcu.constraint_schema = tco.constraint_schema
and kcu.constraint_name = tco.constraint_name
where tco.constraint_type = 'PRIMARY KEY'
- and kcu.table_schema = %s
+ and kcu.table_schema = coalesce(%s, current_schema())
Review Comment:
current_schema() is only the first schema on the search_path that exists, so
with the default "$user", public and a schema named after the login role
(pretty common, like role airflow with schema airflow) it returns that schema
while orders lives in public, and we still get None and []. resolving the table
the way postgres does fixes it
```suggestion
and kcu.table_schema = coalesce(
%s,
(select n.nspname from pg_class c join pg_namespace n on
n.oid = c.relnamespace
where c.oid = to_regclass(quote_ident(%s)))
)
```
plus passing (schema, table, table) to get_records here and the same change
in get_column_names
fixed this plus a test in this commit, you can just cherry pick it instead
of redoing it:
https://github.com/its-amann/airflow/commit/a6e3abaf6c1a99c0fd7d068ab0f95619d7ac1820
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]