Skip to content

Commit 32954bc

Browse files
committed
Ensure sqlTypeCase effects ARRAY[] expression in BigQuery, but not in PostgreSQL
1 parent 5cc191a commit 32954bc

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/syntax/expr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export const exprMap: CstToDocMap<AllExprNodes> = {
176176
interval_expr: (print) => print.spaced(["intervalKw", "expr", "unit"]),
177177
interval_unit_range: (print) => print.spaced(["fromUnit", "toKw", "toUnit"]),
178178
interval_unit: (print) => print("unitKw"),
179+
array_literal_expr: (print) => print(["arrayKw", "expr"]),
179180
array_expr: (print) =>
180181
group(["[", indent([softline, print("expr")]), softline, "]"]),
181182
struct_expr: (print) =>

test/expr/literal.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe("literal", () => {
3939
});
4040

4141
describe("array literals", () => {
42-
it(`formats array literals`, async () => {
42+
it(`formats BigQuery array literals`, async () => {
4343
await testBigquery(
4444
dedent`
4545
SELECT
@@ -51,7 +51,7 @@ describe("literal", () => {
5151
);
5252
});
5353

54-
it(`formats long array literal to multiple lines`, async () => {
54+
it(`formats long BigQuery array literal to multiple lines`, async () => {
5555
await testBigquery(
5656
dedent`
5757
SELECT
@@ -64,6 +64,21 @@ describe("literal", () => {
6464
`,
6565
);
6666
});
67+
68+
it(`formats PostgreSQL array literals`, async () => {
69+
await testPostgresql(
70+
dedent`
71+
SELECT
72+
ARRAY[1, 2, 3],
73+
ARRAY[
74+
'a somewhat large array',
75+
'containing some strings',
76+
'which themselves',
77+
'are somewhat long.'
78+
]
79+
`,
80+
);
81+
});
6782
});
6883

6984
describe("struct literals", () => {

test/options/typeCase.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,39 @@ describe("sqlTypeCase option", () => {
7272
`);
7373
});
7474

75+
it(`does not apply to ARRAY[] literals in PostgreSQL`, async () => {
76+
expect(
77+
await pretty(`SELECT ARRAY[1, 2, 3]`, {
78+
sqlTypeCase: "lower",
79+
dialect: "postgresql",
80+
}),
81+
).toBe(dedent`
82+
SELECT ARRAY[1, 2, 3]
83+
`);
84+
});
85+
86+
it(`applies to ARRAY[] literals in BigQuery`, async () => {
87+
expect(
88+
await pretty(`SELECT ARRAY[1], ARRAY<INT64>[2]`, {
89+
sqlTypeCase: "lower",
90+
dialect: "bigquery",
91+
}),
92+
).toBe(dedent`
93+
SELECT array[1], array<int64>[2]
94+
`);
95+
});
96+
97+
it(`applies to STRUCT() literals in BigQuery`, async () => {
98+
expect(
99+
await pretty(`SELECT STRUCT(2), STRUCT<INT>(2)`, {
100+
sqlTypeCase: "lower",
101+
dialect: "bigquery",
102+
}),
103+
).toBe(dedent`
104+
SELECT struct(2), struct<int>(2)
105+
`);
106+
});
107+
75108
it(`does not apply to SETOF data types`, async () => {
76109
expect(
77110
await pretty(`CREATE TABLE t (x SETOF INT)`, {

0 commit comments

Comments
 (0)