Skip to content

fix: add 13 missing reserved keywords to identifier quoting (#328)#330

Merged
tianzhou merged 1 commit intomainfrom
fix/issue-328-missing-reserved-keywords
Feb 28, 2026
Merged

fix: add 13 missing reserved keywords to identifier quoting (#328)#330
tianzhou merged 1 commit intomainfrom
fix/issue-328-missing-reserved-keywords

Conversation

@tianzhou
Copy link
Contributor

Summary

pgschema dump was not quoting 13 PostgreSQL reserved keywords when used as column identifiers, producing invalid SQL that fails on re-apply.

The reservedWords map in ir/quote.go was missing these keywords that are classified as RESERVED_KEYWORD or TYPE_FUNC_NAME_KEYWORD in PostgreSQL's gram.y:

analyse, analyze, asc, concurrently, desc, full, leading, localtime, localtimestamp, notnull, overlaps, placing, session_user

The fix adds all 13 keywords to the map, cross-referenced against PostgreSQL's gram.y grammar file.

Fixes #328

Test plan

  • Added dump test TestDumpCommand_Issue328MissingReservedKeywords with a table using all 13 keywords as column names
  • Test fails before fix (columns emitted unquoted)
  • Test passes after fix (columns properly quoted)
  • Full dump test suite passes (no regressions)
  • Run: go test -v ./cmd/dump -run TestDumpCommand_Issue328

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 28, 2026 02:54
@greptile-apps
Copy link

greptile-apps bot commented Feb 28, 2026

Greptile Summary

This PR fixes a critical bug where 13 PostgreSQL reserved keywords were not being quoted when used as column identifiers in pgschema dump output, resulting in invalid SQL that fails to execute.

Key Changes:

  • Added 13 missing reserved keywords to reservedWords map in ir/quote.go: analyse, analyze, asc, concurrently, desc, full, leading, localtime, localtimestamp, notnull, overlaps, placing, session_user
  • All keywords verified against PostgreSQL's gram.y grammar file (both reserved_keyword and type_func_name_keyword categories)
  • Added comprehensive integration test with table using all 13 keywords as column names
  • Added local copies of PostgreSQL's gram.y and scan.l for future reference
  • Updated documentation to reflect new reference files and test counts

Impact:
The fix ensures pgschema dump output can be successfully re-applied to PostgreSQL without syntax errors when these keywords are used as identifiers.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The changes are well-tested, thoroughly researched against PostgreSQL's official grammar, and follow established patterns in the codebase. All 13 keywords were verified in internal/gram.y, the fix is minimal and focused, and comprehensive test coverage was added. The implementation is straightforward (adding entries to an existing map) with no risk of regressions.
  • No files require special attention

Important Files Changed

Filename Overview
ir/quote.go Added 13 missing reserved keywords in alphabetical order, matching PostgreSQL's gram.y
cmd/dump/dump_integration_test.go Added comprehensive test for issue #328 verifying all 13 keywords are quoted
testdata/dump/issue_328_missing_reserved_keywords/pgschema.sql Expected pgschema output with all 13 keywords properly quoted

Last reviewed commit: b82af81

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

Fixes invalid SQL emitted by pgschema dump when PostgreSQL reserved keywords are used as column identifiers by ensuring those identifiers are quoted consistently.

Changes:

  • Add 13 missing PostgreSQL reserved keywords to ir/quote.go’s reservedWords map so they get quoted when used as identifiers.
  • Add a new dump integration regression test case (testdata + TestDumpCommand_Issue328MissingReservedKeywords) covering all 13 keywords as column names.
  • Update Claude/skill documentation and add local PostgreSQL lexer reference (internal/scan.l) to support future grammar/keyword investigations.

Reviewed changes

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

Show a summary per file
File Description
ir/quote.go Extends reservedWords with the 13 missing keywords so needsQuoting triggers quoting.
cmd/dump/dump_integration_test.go Adds an integration test to ensure dump output quotes the newly-added reserved keywords.
testdata/dump/issue_328_missing_reserved_keywords/raw.sql New raw schema fixture using all 13 keywords as quoted column names.
testdata/dump/issue_328_missing_reserved_keywords/pgschema.sql New expected pgschema dump output verifying quoted identifiers.
testdata/dump/issue_328_missing_reserved_keywords/pgdump.sql New pg_dump-based setup SQL to reproduce the schema in tests.
testdata/dump/issue_328_missing_reserved_keywords/manifest.json Metadata for the new dump regression test suite.
internal/scan.l Adds a local copy of PostgreSQL’s lexer source as a reference artifact.
CLAUDE.md Updates repository guidance, including references to local Postgres sources and dependencies.
.claude/skills/run_tests/SKILL.md Updates testing guidance to reflect diff.sql/plan files naming.
.claude/skills/postgres_syntax/SKILL.md Updates syntax-reference guidance to prefer local internal/gram.y / internal/scan.l.
.claude/skills/fix_bug/SKILL.md Notes that --generate produces plan artifacts alongside diff.sql.

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

@tianzhou tianzhou force-pushed the fix/issue-328-missing-reserved-keywords branch from b82af81 to ffba098 Compare February 28, 2026 03:04
Add analyse, analyze, asc, concurrently, desc, full, leading, localtime,
localtimestamp, notnull, overlaps, placing, and session_user to the
reservedWords map in ir/quote.go. These are classified as RESERVED_KEYWORD
or TYPE_FUNC_NAME_KEYWORD in PostgreSQL's gram.y and require quoting when
used as column identifiers.

Fixes #328

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tianzhou tianzhou force-pushed the fix/issue-328-missing-reserved-keywords branch from ffba098 to 7983f66 Compare February 28, 2026 03:16
@tianzhou tianzhou merged commit db55199 into main Feb 28, 2026
1 check 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.

pgschema doesn't quote some keywords (e.g desc)

2 participants