Repository navigation
fix(deparser): quote access method names #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
devin-ai-integration
merged 2 commits into
main
from
devin/1794955610-quote-access-method
Nov 17, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
packages/deparser/__tests__/misc/access-method-quoting.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { Deparser } from '../../src'; | ||
| import { expectParseDeparse } from '../../test-utils'; | ||
|
|
||
| // An access method is a name. Parsed SQL only ever yields a plain identifier | ||
| // there, so the hostile values live in hand-built ASTs, not a fixture. | ||
|
|
||
| const smuggled = 'btree (a); DROP TABLE t; --'; | ||
| const quoted = `USING "${smuggled}"`; | ||
|
|
||
| const relation = { relname: 't', inh: true, relpersistence: 'p' }; | ||
| const indexParams = [{ IndexElem: { name: 'a', ordering: 'SORTBY_DEFAULT', nulls_ordering: 'SORTBY_NULLS_DEFAULT' } }]; | ||
|
|
||
| describe('access method names in hand-built ASTs', () => { | ||
| it.each<[string, any]>([ | ||
| ['IndexStmt', { IndexStmt: { idxname: 'i', relation, accessMethod: smuggled, indexParams } }], | ||
| ['CreateStmt', { CreateStmt: { relation, accessMethod: smuggled, oncommit: 'ONCOMMIT_NOOP' } }], | ||
| [ | ||
| 'exclusion Constraint', | ||
| { | ||
| AlterTableStmt: { | ||
| relation, | ||
| objtype: 'OBJECT_TABLE', | ||
| cmds: [{ | ||
| AlterTableCmd: { | ||
| subtype: 'AT_AddConstraint', | ||
| behavior: 'DROP_RESTRICT', | ||
| def: { | ||
| Constraint: { | ||
| contype: 'CONSTR_EXCLUSION', | ||
| conname: 'c', | ||
| access_method: smuggled, | ||
| exclusions: [{ List: { items: [indexParams[0], { List: { items: [{ String: { sval: '=' } }] } }] } }] | ||
| } | ||
| } | ||
| } | ||
| }] | ||
| } | ||
| } | ||
| ] | ||
| ])('quotes a %s access method that is not a plain identifier', (_label, node) => { | ||
| const sql = Deparser.deparse(node); | ||
| expect(sql).toContain(quoted); | ||
| expect(sql.replace(quoted, '')).not.toContain(';'); | ||
| }); | ||
|
|
||
| it.each([ | ||
| 'CREATE INDEX i ON t USING gin (a)', | ||
| 'CREATE INDEX i ON t USING hnsw (a vector_cosine_ops)', | ||
| 'CREATE INDEX i ON t USING ivfflat (a vector_cosine_ops) WITH (lists = 100)', | ||
| 'CREATE INDEX i ON t USING bm25 (a) WITH (k1 = 1.2)', | ||
| 'CREATE INDEX i ON t USING "Odd Name" (a)', | ||
| 'ALTER TABLE t ADD CONSTRAINT c EXCLUDE USING gist (a WITH =)', | ||
| 'CREATE TABLE t (a int) USING heap', | ||
| 'ALTER OPERATOR FAMILY f USING btree RENAME TO g', | ||
| 'ALTER OPERATOR FAMILY f USING "Odd Name" RENAME TO g', | ||
| 'DROP OPERATOR CLASS c USING "Odd Name"', | ||
| 'COMMENT ON OPERATOR CLASS c USING "Odd Name" IS \'x\'', | ||
| 'COMMENT ON OPERATOR FAMILY s.f USING "Odd Name" IS \'x\'' | ||
| ])('round-trips %s', async (sql) => { | ||
| await expectParseDeparse(sql); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 bug · medium
Handle schema-qualified opclass rename/owner lists
RenameStmt(packages/deparser/src/deparser.ts:8536) andAlterOwnerStmt(line 8611) special-case operator class/family objects only when the object List has exactly 2 items; a 3-item schema-qualified list (accessMethod, schema, name) falls through to the genericListvisit, which emits the parts without the requiredUSING access_methodsuffix.ALTER OPERATOR FAMILY s.f USING btree RENAME TO gis valid PostgreSQL and deparses to SQL that does not reparse. The siblingDropStmtpath (line 4748) handles the 3-item shape, so coverage is inconsistent across the same statement family.📋 Prompt for AI Agents
In packages/deparser/src/deparser.ts, extend the OPFAMILY/OPCLASS handling in
RenameStmt(lines 8534-8542) andAlterOwnerStmt(lines 8609-8617) to handleitems.length === 3by emittingQuoteUtils.quoteQualifiedIdentifier(items[1].String.sval, items[2].String.sval) USING QuoteUtils.quoteIdentifier(items[0].String.sval), matching the existing pattern at line 4748 in DropStmt. Add round-trip tests for the schema-qualified RENAME and OWNER TO forms in packages/deparser/tests/misc/access-method-quoting.test.ts.