Skip to content

PostgreSQL schema discovery fails with mixed-case table names #7565

@eroshenko

Description

@eroshenko

Technical details:

  • Redash Version: 25.8.0
  • Browser/OS: Google Chrome/CentOS
  • How did you install Redash: Docker Image

Description:

When using PostgreSQL with tables containing mixed-case (camelCase) names, the automatic schema discovery fails with permission errors. The issue occurs in the system query that checks table privileges.

Problem:

The current query uses:
sql
AND has_table_privilege(s.nspname || '.' || c.relname, 'select')
This fails for table names like MyTable or mySchema.MyTable because has_table_privilege requires properly quoted identifiers when names contain uppercase letters or special characters.

Error example:

For a table named MyMixedCaseTable, the current code generates:
sql
has_table_privilege('public.MyMixedCaseTable', 'select') -- FAILS
But it should be:
sql
has_table_privilege('"public"."MyMixedCaseTable"', 'select') -- WORKS

Fix as I think:

In redash/query_runner/pg.py, replace:
"AND has_table_privilege(s.nspname || '.' || c.relname, 'select')"
with:
"AND has_table_privilege(quote_ident(s.nspname) || '.' || quote_ident(c.relname), 'select')"

Addon:

• The quote_ident() function properly handles identifiers with mixed case, spaces, or special characters
• This affects the schema discovery for materialized views, foreign tables, and partitioned tables (relkind IN ('m', 'f', 'p'))
• The same issue might exist in other parts of the PostgreSQL query runner

Thank you for your attention

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions