Skip to content

fix(postgres): Auto-quote mixed-case identifiers to prevent lowercase… - #11786

Closed
Nikhil172913832 wants to merge 4 commits into
mindsdb:mainfrom
Nikhil172913832:fixing_issue_11599
Closed

Nikhil172913832 wants to merge 4 commits into
mindsdb:mainfrom
Nikhil172913832:fixing_issue_11599

Conversation

@Nikhil172913832

Copy link
Copy Markdown

Description

PostgreSQL folds unquoted identifiers to lowercase, causing "relation not found" errors when querying case-sensitive tables/columns created with quoted identifiers (e.g., CREATE TABLE "Notes"). This fix automatically quotes identifiers containing uppercase letters in the PostgreSQL dialect to preserve case according to PostgreSQL specification.

Changes:

  • Modified sqlalchemy_render.py to auto-quote PostgreSQL identifiers with uppercase letters
  • Updated tests to reflect correct PostgreSQL quoting behavior per official documentation

Fixes #11599

Type of change

(Please delete options that are not relevant)

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ⚡ New feature (non-breaking change which adds functionality)
  • 📢 Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • 📄 This change requires a documentation update

Verification Process

To ensure the changes are working as expected:

  • Test Location: tests/unit/render/test_sqlalchemyrender.py
  • Verification Steps:
    1. Create a PostgreSQL table with quoted uppercase identifier: CREATE TABLE "Notes" (id INT, content TEXT)
    2. Query the table through MindsDB: SELECT * FROM Notes
    3. Verify the generated SQL quotes the identifier: SELECT * FROM "Notes" (preserves case)
    4. Run unit tests: python -m pytest tests/unit/render/test_sqlalchemyrender.py -v
    5. All 13 tests should pass

Additional Media:

  • I have attached a brief loom video or screenshots showcasing the new functionality or change.

Checklist:

  • My code follows the style guidelines(PEP 8) of MindsDB.
  • I have appropriately commented on my code, especially in complex areas.
  • Necessary documentation updates are either made or tracked in issues.
  • Relevant unit and integration tests are updated or added.

@github-actions

github-actions Bot commented Oct 24, 2025 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Nikhil172913832

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Oct 24, 2025
@entelligence-ai-pr-reviews

Copy link
Copy Markdown
Contributor

🔒 Entelligence AI Vulnerability Scanner

✅ No security vulnerabilities found!

Your code passed our comprehensive security analysis.

📊 Files Analyzed: 1 files


Comment thread mindsdb/utilities/render/sqlalchemy_render.py Outdated
Nikhil172913832 and others added 2 commits October 24, 2025 21:47
Co-authored-by: entelligence-ai-pr-reviews[bot] <174136889+entelligence-ai-pr-reviews[bot]@users.noreply.github.com>
@ZoranPandovski
ZoranPandovski requested a review from ea-rus October 27, 2025 11:38
@Nikhil172913832

Copy link
Copy Markdown
Author

Hi @ea-rus, just wanted to check if you could take a look at this PR when you get a chance.

query = Select(targets=[Identifier("Test", alias=Identifier("Test2"))])
rendered = SqlalchemyRender("postgres").get_string(query, with_failback=False)
assert rendered == "SELECT Test AS Test2"
assert rendered == 'SELECT "Test" AS "Test2"'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't add quotes where they didn't existed before parsing
quotes should exist in input sql.
the problem is:

  • if backticks are used in input sql - the query is rendered with doubleqoutes
  • if doubleqoutes are used - the query doesn't have info about them and it is rendered without them

To fix it I came up to solution on the parser side: mindsdb/mindsdb_sql_parser#70

@martyna-mindsdb
martyna-mindsdb requested a review from StpMax March 26, 2026 13:39
@ea-rus

ea-rus commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

This update is not required, we won't support double quotes as escape symbols
mindsdb/mindsdb_sql_parser#84

@ea-rus ea-rus closed this Mar 26, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Quoted column name rewritten to lowercase (relation not found)

2 participants