Skip to content

Commit

Permalink
Fix CREATE VIEW IF NOT EXISTS test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nene committed Dec 7, 2023
1 parent 3e0689c commit 3f62841
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/languages/postgresql/postgresql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const reservedClauses = expandPhrases([
'SET',
// Data definition
'CREATE [OR REPLACE] [TEMP | TEMPORARY] [RECURSIVE] VIEW',
'CREATE MATERIALIZED VIEW [IF NOT EXISTS]',
'CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]',
// other
'RETURNING',
]);
Expand Down
9 changes: 6 additions & 3 deletions test/features/createView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ export default function supportsCreateView(
}

if (ifNotExists) {
it('formats short CREATE TABLE IF NOT EXISTS', () => {
expect(format('CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent`
CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);
it('formats short CREATE VIEW IF NOT EXISTS', () => {
expect(format('CREATE VIEW IF NOT EXISTS my_view AS SELECT 42;')).toBe(dedent`
CREATE VIEW IF NOT EXISTS
my_view AS
SELECT
42;
`);
});
}
Expand Down

0 comments on commit 3f62841

Please sign in to comment.