Skip to content

Commit 9dcc393

Browse files
committed
Format RAISE with format string
1 parent 6aac9fb commit 9dcc393

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/syntax/other_clauses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const otherClausesMap: CstToDocMap<AllOtherClauses> = {
1919
return [print("asKw"), indent([hardline, print("expr")])];
2020
},
2121

22-
comma_clause: (print) => [",", print("expr")],
22+
comma_clause: (print) => group([",", indent([line, print("expr")])]),
2323

2424
// WHERE CURRENT OF clause
2525
where_current_of_clause: (print) =>

src/syntax/procedural_language.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export const proceduralLanguageMap: Partial<CstToDocMap<AllProceduralNodes>> = {
7373

7474
error_bigquery: (print) => print("errorKw"),
7575
error_name: (print) => print("name"),
76-
error_sqlstate: (print) => print.spaced(["sqlstateKw", "code"]),
77-
76+
error_sqlstate: (print) => group(print.spaced(["sqlstateKw", "code"])),
77+
error_format_string: (print, node) => group(print(["format", "args"])),
7878
// SET
7979
set_stmt: (print) => group(print.spaced(["setKw", "assignments"])),
8080

test/proc/raise.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,25 @@ describe("raise", () => {
4242
DETAIL = 'The index you provided is 10, but the maximum allowed is 5'
4343
`);
4444
});
45+
46+
it(`formats RAISE with plain string`, async () => {
47+
await testPlpgsql(dedent`
48+
RAISE 'An error occurred while processing your request'
49+
`);
50+
});
51+
52+
it(`formats RAISE format string`, async () => {
53+
await testPlpgsql(dedent`
54+
RAISE 'Index % is out of range in %', idx, array_name
55+
`);
56+
});
57+
58+
it(`formats RAISE format string with long arguments`, async () => {
59+
await testPlpgsql(dedent`
60+
RAISE 'Index % is out of range in %. %',
61+
idx,
62+
array_name,
63+
'Please check the index and try again'
64+
`);
65+
});
4566
});

0 commit comments

Comments
 (0)