Skip to content

fix: reserved keyword not quoted in online rewrite DDL (#286)#291

Merged
tianzhou merged 1 commit intomainfrom
fix/issue-286-reserved-keyword-quoting
Feb 16, 2026
Merged

fix: reserved keyword not quoted in online rewrite DDL (#286)#291
tianzhou merged 1 commit intomainfrom
fix/issue-286-reserved-keyword-quoting

Conversation

@tianzhou
Copy link
Contributor

Summary

  • The getTableNameWithSchema helper in internal/plan/rewrite.go was returning raw table/schema names without calling ir.QuoteIdentifier(), causing reserved keywords like order to produce invalid SQL in online rewrite operations (CREATE INDEX CONCURRENTLY, constraint rewrites, FK rewrites, NOT NULL rewrites, identity column rewrites)
  • The equivalent function in internal/diff/diff.go already quoted correctly, so only the plan rewrite path was affected

Fixes #286

Test plan

  • Added testdata/diff/online/issue_286_reserved_keyword_quoting/ test case with a table named order (reserved keyword) that gets a new column with FK and an index
  • Diff test passes: PGSCHEMA_TEST_FILTER="online/issue_286_reserved_keyword_quoting" go test -v ./internal/diff -run TestDiffFromFiles
  • Plan test passes (including apply verification): PGSCHEMA_TEST_FILTER="online/issue_286_reserved_keyword_quoting" go test -v ./cmd -run TestPlanAndApply
  • All online tests pass: PGSCHEMA_TEST_FILTER="online/" go test -v ./cmd -run TestPlanAndApply
  • Full test suite passes (no regressions)

🤖 Generated with Claude Code

The `getTableNameWithSchema` helper in `internal/plan/rewrite.go` was
returning raw table names without quoting, causing reserved keywords
like `order` to produce invalid SQL in online rewrite operations
(CREATE INDEX CONCURRENTLY, constraint rewrites, etc.).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 16, 2026 08:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where reserved keyword table names (like order) were not being properly quoted in online rewrite DDL operations such as CREATE INDEX CONCURRENTLY, foreign key rewrites, constraint rewrites, NOT NULL rewrites, and identity column rewrites. The fix ensures that getTableNameWithSchema in internal/plan/rewrite.go properly quotes identifiers using ir.QuoteIdentifier(), matching the behavior already implemented in internal/diff/diff.go.

Changes:

  • Modified getTableNameWithSchema helper function to quote table and schema names using ir.QuoteIdentifier()
  • Added comprehensive test case with a table named order (a reserved keyword) to verify the fix

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/plan/rewrite.go Fixed getTableNameWithSchema to quote table and schema identifiers, preventing SQL syntax errors with reserved keywords
testdata/diff/online/issue_286_reserved_keyword_quoting/old.sql Test setup: defines a table named order (reserved keyword) with basic columns
testdata/diff/online/issue_286_reserved_keyword_quoting/new.sql Test setup: adds a column with FK constraint and index to the order table
testdata/diff/online/issue_286_reserved_keyword_quoting/plan.txt Expected output: verifies table name is quoted in all DDL statements
testdata/diff/online/issue_286_reserved_keyword_quoting/plan.sql Expected output: verifies table name is quoted in SQL plan
testdata/diff/online/issue_286_reserved_keyword_quoting/plan.json Expected output: verifies table name is quoted in JSON plan
testdata/diff/online/issue_286_reserved_keyword_quoting/diff.sql Expected output: verifies table name is quoted in diff SQL

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tianzhou tianzhou merged commit e700a79 into main Feb 16, 2026
7 checks passed
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.

reserved keyword double quote inconsistency

1 participant