Skip to content

Commit

Permalink
Add handling for ALTER statements with BEGIN in SQL parser
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Jan 9, 2025
1 parent 184ef2b commit e24853b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/language/sql/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export default class Document {
break;
}

if (upperValue === `BEGIN` && currentStatementType === StatementType.Alter) {
break;
}

// We include BEGIN in the current statement
// then the next statement beings
const statementTokens = tokens.slice(statementStart, i+1);
Expand Down
17 changes: 16 additions & 1 deletion src/language/sql/tests/blocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,19 @@ test('CREATE statements', () => {

const groups = doc.getStatementGroups();
expect(groups.length).toBe(3);
});
});

test(`ALTER with BEGIN`, () => {
const lines = [
`ALTER TABLE mylongtable1`,
` ADD COLUMN ib TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW BEGIN`,
` ADD COLUMN ie TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW END`,
` ADD COLUMN tid TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS TRANSACTION START`,
` ID`,
` ADD PERIOD SYSTEM_TIME (ib, ie);`,
].join(`\n`);

const doc = new Document(lines);
const groups = doc.getStatementGroups();
expect(groups.length).toBe(1);
})

0 comments on commit e24853b

Please sign in to comment.