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
1 change: 1 addition & 0 deletions src/languages/postgresql/postgresql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT]']);
const reservedClauses = expandPhrases([
// queries
'WITH [RECURSIVE]',
'INTO [TEMPORARY | TEMP | UNLOGGED] [TABLE]',
'FROM',
'WHERE',
'GROUP BY [ALL | DISTINCT]',
Expand Down
38 changes: 38 additions & 0 deletions test/postgresql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,44 @@ describe('PostgreSqlFormatter', () => {
const language = 'postgresql';
const format: FormatFn = (query, cfg = {}) => originalFormat(query, { ...cfg, language });

// Issue #864
it.each([
'INTO',
'INTO TABLE',
'INTO TEMP',
'INTO TEMP TABLE',
'INTO TEMPORARY',
'INTO TEMPORARY TABLE',
'INTO UNLOGGED',
'INTO UNLOGGED TABLE',
])('formats SELECT %s on a separate line', into => {
const result = format(`SELECT id, name ${into} new_users FROM users WHERE active;`);
expect(result).toBe(dedent`
SELECT
id,
name
${into}
new_users
FROM
users
WHERE
active;
`);
expect(format(result)).toBe(result);
});

it('formats the case of SELECT INTO modifiers', () => {
expect(format('select id into temporary table new_users from users;', { keywordCase: 'upper' }))
.toBe(dedent`
SELECT
id
INTO TEMPORARY TABLE
new_users
FROM
users;
`);
});

behavesLikePostgresqlFormatter(format);
supportsCreateView(format, { orReplace: true, materialized: true, ifNotExists: true });
supportsCreateTable(format, { ifNotExists: true });
Expand Down