From ad780212bdfc92f466f288c18eeb50c9f8dbf8c7 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Tue, 14 Nov 2023 14:18:20 +0200 Subject: [PATCH] Fix formatting of parameterized TIMESTAMP() WITH TIME ZONE Fixes #618 --- src/languages/postgresql/postgresql.formatter.ts | 2 +- test/postgresql.test.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/languages/postgresql/postgresql.formatter.ts b/src/languages/postgresql/postgresql.formatter.ts index 38909b835f..700d8b9791 100644 --- a/src/languages/postgresql/postgresql.formatter.ts +++ b/src/languages/postgresql/postgresql.formatter.ts @@ -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', ]); diff --git a/test/postgresql.test.ts b/test/postgresql.test.ts index cce7bf8c96..607f376a97 100644 --- a/test/postgresql.test.ts +++ b/test/postgresql.test.ts @@ -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 ); `); });