rusackas commented on code in PR #42312:
URL: https://github.com/apache/superset/pull/42312#discussion_r3651608472


##########
superset/db_engine_specs/postgres.py:
##########
@@ -793,6 +793,29 @@ def get_catalog_names(
                 )
             }
 
+    @classmethod
+    def get_schema_names(cls, inspector: Inspector) -> set[str]:
+        """
+        Return all schema names, excluding the ``pg_``-prefixed Postgres
+        system schemas (e.g. ``pg_catalog``, ``pg_toast``).
+
+        SQLAlchemy's Postgres dialect filters out system schemas with the
+        query ``nspname NOT LIKE 'pg_%'``. Since ``_`` is a single-character
+        wildcard in SQL ``LIKE`` patterns, this unintentionally excludes any
+        user-defined schema that merely starts with ``pg`` followed by any
+        other character (e.g. ``pgsql``, ``pgstats``), not only the
+        ``pg_``-prefixed system schemas. Matching on the literal ``pg_``
+        prefix instead keeps those user-defined schemas.
+        """
+        with inspector.engine.connect() as conn:
+            return {
+                name
+                for (name,) in conn.execute(
+                    text("SELECT nspname FROM pg_namespace ORDER BY nspname")
+                )
+                if not name.startswith("pg_")
+            }

Review Comment:
   Postgres itself blocks `CREATE SCHEMA` for names literally prefixed with 
`pg_` (regular users get an error), so `pg_custom` isn't really a reachable 
scenario. The docstring and the test at line 408 spell out that tradeoff on 
purpose, this PR is just fixing the `LIKE` wildcard bug for things like 
`pgsql`/`pgstats`, not opening up literal `pg_` names.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to