Skip to content

Commit 3f62841

Browse files
committed
Fix CREATE VIEW IF NOT EXISTS test
And also tweak the Postgres definition. Although IF NOT EXISTS only works for MATERIALIZED view, it'll be simpler to test when we also support IF NOT EXISTS for normal views.
1 parent 3e0689c commit 3f62841

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/languages/postgresql/postgresql.formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const reservedClauses = expandPhrases([
2727
'SET',
2828
// Data definition
2929
'CREATE [OR REPLACE] [TEMP | TEMPORARY] [RECURSIVE] VIEW',
30-
'CREATE MATERIALIZED VIEW [IF NOT EXISTS]',
30+
'CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]',
3131
// other
3232
'RETURNING',
3333
]);

test/features/createView.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ export default function supportsCreateView(
5959
}
6060

6161
if (ifNotExists) {
62-
it('formats short CREATE TABLE IF NOT EXISTS', () => {
63-
expect(format('CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent`
64-
CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);
62+
it('formats short CREATE VIEW IF NOT EXISTS', () => {
63+
expect(format('CREATE VIEW IF NOT EXISTS my_view AS SELECT 42;')).toBe(dedent`
64+
CREATE VIEW IF NOT EXISTS
65+
my_view AS
66+
SELECT
67+
42;
6568
`);
6669
});
6770
}

0 commit comments

Comments
 (0)