Skip to content

Commit

Permalink
Fix formatting of parameterized TIMESTAMP() WITH TIME ZONE
Browse files Browse the repository at this point in the history
Fixes #618
  • Loading branch information
nene committed Nov 14, 2023
1 parent 723e9dd commit ad78021
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/languages/postgresql/postgresql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const reservedPhrases = expandPhrases([
'ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]',
'{ROWS | RANGE | GROUPS} BETWEEN',
// https://www.postgresql.org/docs/current/datatype-datetime.html
'{TIMESTAMP | TIME} {WITH | WITHOUT} TIME ZONE',
'[TIMESTAMP | TIME] {WITH | WITHOUT} TIME ZONE',
// comparison operator
'IS [NOT] DISTINCT FROM',
]);
Expand Down
13 changes: 8 additions & 5 deletions test/postgresql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,21 @@ describe('PostgreSqlFormatter', () => {
`);
});

// Regression test for issue #391
// Regression test for issues #391 and #618
it('formats TIMESTAMP WITH TIME ZONE syntax', () => {
expect(
format(
'CREATE TABLE time_table (id INT, created_at TIMESTAMP WITH TIME ZONE, deleted_at TIME WITH TIME ZONE);'
)
format(`
CREATE TABLE time_table (id INT,
created_at TIMESTAMP WITH TIME ZONE,
deleted_at TIME WITH TIME ZONE,
modified_at TIMESTAMP(0) WITH TIME ZONE);`)
).toBe(dedent`
CREATE TABLE
time_table (
id INT,
created_at TIMESTAMP WITH TIME ZONE,
deleted_at TIME WITH TIME ZONE
deleted_at TIME WITH TIME ZONE,
modified_at TIMESTAMP(0) WITH TIME ZONE
);
`);
});
Expand Down

0 comments on commit ad78021

Please sign in to comment.