diff --git a/src/parser.ts b/src/parser.ts index f382823..14dffa5 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -673,7 +673,7 @@ function stateMachineStatementParser( if ( token.type === 'keyword' && - blockOpeners[dialect].includes(token.value) && + blockOpeners[dialect].includes(token.value.toUpperCase()) && prevNonWhitespaceToken?.value.toUpperCase() !== 'END' && (token.value.toUpperCase() !== 'BEGIN' || (token.value.toUpperCase() === 'BEGIN' && diff --git a/test/identifier/single-statement.spec.ts b/test/identifier/single-statement.spec.ts index 47be0dc..b652937 100644 --- a/test/identifier/single-statement.spec.ts +++ b/test/identifier/single-statement.spec.ts @@ -1381,6 +1381,30 @@ describe('identifier', () => { expect(actual).to.eql(expected); }); + it('Should parse lower case block opener in query correctly', () => { + const sql = `CREATE OR REPLACE PROCEDURE foo.bar (col string) + BEGIN + if foo is not null then + SET foo = 'bar'; + end if; + + SELECT 1; + END;`; + const actual = identify(sql, { dialect: 'bigquery', strict: false }); + const expected = [ + { + start: 0, + end: 170, + text: sql, + type: 'CREATE_PROCEDURE', + executionType: 'MODIFICATION', + parameters: [], + }, + ]; + + expect(actual).to.eql(expected); + }); + it('Should identify a lone END', () => { const sql = 'END;'; const actual = identify(sql, { strict: false });