Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/languages/mariadb/likeMariaDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export function postProcess(tokens: Token[]) {
// This is SET datatype, not SET statement
return { ...token, type: TokenType.RESERVED_FUNCTION_NAME };
}
if (isToken.INTERVAL(token) && nextToken.text === '(') {
// This is INTERVAL() function, not INTERVAL expression
return { ...token, type: TokenType.RESERVED_FUNCTION_NAME };
}
const prevToken = tokens[i - 1] || EOF_TOKEN;
if (isToken.VALUES(token) && prevToken.text === '=') {
// This is VALUES() function, not VALUES clause
Expand Down
1 change: 0 additions & 1 deletion src/languages/mysql/mysql.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export const functions: string[] = [
'INTERNAL_MAX_DATA_LENGTH',
'INTERNAL_TABLE_ROWS',
'INTERNAL_UPDATE_TIME',
'INTERVAL',
'IS',
'IS_FREE_LOCK',
'IS_IPV4',
Expand Down
1 change: 0 additions & 1 deletion src/languages/singlestoredb/singlestoredb.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export const functions: string[] = [
'INITCAP',
'INSERT',
'INSTR',
'INTERVAL',
'IS',
'IS NULL',
'JSON_AGG',
Expand Down
1 change: 0 additions & 1 deletion src/languages/tidb/tidb.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const functions: string[] = [
'INSERT_FUNC',
'INSTR',
'INTDIV',
'INTERVAL',
'IS_FREE_LOCK',
'IS_IPV4',
'IS_IPV4_COMPAT',
Expand Down
1 change: 1 addition & 0 deletions src/lexer/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const testToken =
export const isToken = {
ARRAY: testToken({ text: 'ARRAY', type: TokenType.RESERVED_DATA_TYPE }),
BY: testToken({ text: 'BY', type: TokenType.RESERVED_KEYWORD }),
INTERVAL: testToken({ text: 'INTERVAL', type: TokenType.RESERVED_KEYWORD }),
SET: testToken({ text: 'SET', type: TokenType.RESERVED_CLAUSE }),
STRUCT: testToken({ text: 'STRUCT', type: TokenType.RESERVED_DATA_TYPE }),
WINDOW: testToken({ text: 'WINDOW', type: TokenType.RESERVED_CLAUSE }),
Expand Down
15 changes: 15 additions & 0 deletions test/behavesLikeMariaDbFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,19 @@ export default function behavesLikeMariaDbFormatter(format: FormatFn) {
GRANT ALL ON *.* TO user2;
`);
});

// Issue #985
it('treats INTERVAL as keyword and INTERVAL() as function', () => {
expect(
format(`select now() - interval 30 day, date_sub(d, interval 1 hour), interval(5, 1, 10);`, {
keywordCase: 'upper',
functionCase: 'lower',
})
).toBe(dedent`
SELECT
now() - INTERVAL 30 day,
date_sub(d, INTERVAL 1 hour),
interval(5, 1, 10);
`);
});
}