Skip to content

Commit 6aac9fb

Browse files
committed
Format RAISE statement
1 parent e5c0562 commit 6aac9fb

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/syntax/procedural_language.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,14 @@ export const proceduralLanguageMap: Partial<CstToDocMap<AllProceduralNodes>> = {
193193
}
194194
},
195195
// RAISE
196-
raise_stmt: (print) => group(print.spaced(["raiseKw", "using"])),
197-
raise_using_clause: (print) => group(print.spaced(["usingKw", "options"])),
196+
raise_stmt: (print, node) =>
197+
group([
198+
print.spaced(["raiseKw", "level", "error"]),
199+
node.using ? indent([line, print("using")]) : [],
200+
]),
201+
raise_level: (print) => print("levelKw"),
202+
raise_using_clause: (print) =>
203+
group([print("usingKw"), indent([line, print("options")])]),
198204
raise_option_element: (print) => [print("nameKw"), " = ", print("value")],
199205
// ASSERT
200206
assert_stmt: (print) =>

test/proc/raise.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dedent from "dedent-js";
2-
import { testBigquery } from "../test_utils";
2+
import { testBigquery, testPlpgsql } from "../test_utils";
33

44
describe("raise", () => {
55
it(`formats RAISE statement`, async () => {
@@ -13,4 +13,33 @@ describe("raise", () => {
1313
RAISE USING MESSAGE = 'Serious error!'
1414
`);
1515
});
16+
17+
it(`formats RAISE with condition name`, async () => {
18+
await testPlpgsql(dedent`
19+
RAISE division_by_zero
20+
`);
21+
});
22+
23+
it(`formats RAISE with SQLSTATE`, async () => {
24+
await testPlpgsql(dedent`
25+
RAISE SQLSTATE 'P0001'
26+
`);
27+
});
28+
29+
it(`formats RAISE with level and USING clause`, async () => {
30+
await testPlpgsql(dedent`
31+
RAISE WARNING index_out_of_range
32+
USING MESSAGE = 'Index is out of range', HINT = 'Whatever'
33+
`);
34+
});
35+
36+
it(`formats RAISE with long USING clause`, async () => {
37+
await testPlpgsql(dedent`
38+
RAISE index_out_of_range
39+
USING
40+
MESSAGE = 'Index is out of range',
41+
HINT = 'Please check the index and try again',
42+
DETAIL = 'The index you provided is 10, but the maximum allowed is 5'
43+
`);
44+
});
1645
});

0 commit comments

Comments
 (0)