Skip to content

Conversation

@pyramation
Copy link
Collaborator

@pyramation pyramation commented Jun 23, 2025

Fix Catalogname Handling in RangeVar for Three-Part Table Names

Summary

Fixed failing deparser test in misc-issues.test.ts by implementing missing catalogname support in RangeVar nodes, enabling proper handling of three-part table names (catalog.schema.table) in PostgreSQL SQL statements.

Changes Made

  • Enhanced RangeVar deparser method: Added catalogname support to handle three-part table names
  • Fixed table name construction logic: Now properly builds catalog.schema.table format when catalogname is present
  • Updated TESTS.md: Added documentation for catalogname support and updated test results

Technical Details

The issue was in the RangeVar method in deparser.ts where the table name construction only handled schemaname.relname but ignored catalogname. The fix adds proper catalogname handling:

if (node.catalogname) {
  tableName = QuoteUtils.quote(node.catalogname);
  if (node.schemaname) {
    tableName += '.' + QuoteUtils.quote(node.schemaname);
  }
  tableName += '.' + QuoteUtils.quote(node.relname);
}

Test Results

  • Before: misc/issues-7.sql failed - SELECT * from foo.bar.baz deparsed as SELECT * FROM bar.baz (missing catalogname)
  • After: misc/issues-7.sql passes - SELECT * from foo.bar.baz correctly deparsed as SELECT * FROM foo.bar.baz
  • Overall: 254/254 tests passing (100%)

Verification

cd packages/deparser
yarn test --testNamePattern="misc-issues"  # ✅ PASS
yarn test  # ✅ 254/254 tests passing

The AST comparison now succeeds for the parse/deparse/reparse cycle, confirming that catalogname is properly preserved in the deparser output.

Link to Devin run

https://app.devin.ai/sessions/e2a49c9a83094092a217b1c66ad778de

Requested by: Dan Lynch (pyramation@gmail.com)

pyramation and others added 6 commits June 22, 2025 21:05
- Add support for nulls_not_distinct property in UNIQUE constraint handler
- Resolves AST mismatch issues in misc-issues test for PostgreSQL 17 features
- All 254/254 deparser tests now passing (100%)

Co-Authored-By: Dan Lynch <pyramation@gmail.com>
- Add catalogname support to RangeVar deparser method
- Handle catalog.schema.table format properly in SQL output
- Fix misc/issues-7.sql test: 'SELECT * from foo.bar.baz' now correctly includes catalogname
- All 254/254 tests now passing (100%)
- Update TESTS.md to reflect catalogname support

Co-Authored-By: Dan Lynch <pyramation@gmail.com>
@pyramation pyramation closed this Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants