Skip to content

Commit 077575b

Browse files
committed
Add CASE expression support for Redshift
For reference: https://docs.aws.amazon.com/redshift/latest/dg/r_CASE_function.html
1 parent 0e5cfba commit 077575b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/languages/redshift.formatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const reservedFunctions = {
3838
// https://docs.aws.amazon.com/redshift/latest/dg/c_bitwise_aggregate_functions.html
3939
bitwise: ['BIT_AND', 'BIT_OR', 'BOOL_AND', 'BOOL_OR'],
4040
// https://docs.aws.amazon.com/redshift/latest/dg/c_conditional_expressions.html
41-
conditional: ['CASE', 'COALESCE', 'DECODE', 'GREATEST', 'LEAST', 'NVL', 'NVL2', 'NULLIF'],
41+
conditional: ['COALESCE', 'DECODE', 'GREATEST', 'LEAST', 'NVL', 'NVL2', 'NULLIF'],
4242
// https://docs.aws.amazon.com/redshift/latest/dg/Date_functions_header.html
4343
dateTime: [
4444
'ADD_MONTHS',
@@ -634,7 +634,6 @@ const reservedCommands = [
634634
'DROP USER',
635635
'DROP VIEW',
636636
'DROP',
637-
'END',
638637
'EXECUTE',
639638
'EXPLAIN',
640639
'FETCH',
@@ -745,6 +744,7 @@ export default class RedshiftFormatter extends Formatter {
745744
stringTypes: RedshiftFormatter.stringTypes,
746745
blockStart: RedshiftFormatter.blockStart,
747746
blockEnd: RedshiftFormatter.blockEnd,
747+
supportsCase: true,
748748
indexedPlaceholderTypes: RedshiftFormatter.indexedPlaceholderTypes,
749749
namedPlaceholderTypes: RedshiftFormatter.namedPlaceholderTypes,
750750
lineCommentTypes: RedshiftFormatter.lineCommentTypes,

test/redshift.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import supportsOperators from './features/operators';
1111
import supportsSchema from './features/schema';
1212
import supportsStrings from './features/strings';
1313
import supportsDeleteFrom from './features/deleteFrom';
14+
import supportsCase from './features/case';
1415

1516
describe('RedshiftFormatter', () => {
1617
const language = 'redshift';
1718
const format: FormatFn = (query, cfg = {}) => originalFormat(query, { ...cfg, language });
1819

1920
behavesLikeSqlFormatter(language, format);
21+
supportsCase(language, format);
2022
supportsCreateTable(language, format);
2123
supportsAlterTable(language, format);
2224
supportsAlterTableModify(language, format);

0 commit comments

Comments
 (0)