From c3c76b665e7e7e443bf650711c252deede0b9314 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Mon, 23 Oct 2023 18:04:28 +0300 Subject: [PATCH] Support array slice operator in Postgres Fixes #624 --- src/languages/postgresql/postgresql.formatter.ts | 3 ++- test/postgresql.test.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/languages/postgresql/postgresql.formatter.ts b/src/languages/postgresql/postgresql.formatter.ts index 768e32e16e..4ea02dc43a 100644 --- a/src/languages/postgresql/postgresql.formatter.ts +++ b/src/languages/postgresql/postgresql.formatter.ts @@ -357,10 +357,11 @@ export const postgresql: DialectOptions = { '<->>>', // Type cast '::', + ':', ], }, formatOptions: { - alwaysDenseOperators: ['::'], + alwaysDenseOperators: ['::', ':'], onelineClauses, }, }; diff --git a/test/postgresql.test.ts b/test/postgresql.test.ts index f875bb1a24..b3dc4adaad 100644 --- a/test/postgresql.test.ts +++ b/test/postgresql.test.ts @@ -233,6 +233,17 @@ describe('PostgreSqlFormatter', () => { `); }); + // Regression test for issue #624 + it('supports array slice operator', () => { + expect(format('SELECT foo[:5], bar[1:], baz[1:5], zap[:];')).toBe(dedent` + SELECT + foo[:5], + bar[1:], + baz[1:5], + zap[:]; + `); + }); + it('formats ALTER TABLE ... ALTER COLUMN', () => { expect( format(