Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ create_table_stmt
name:(__ entity_name)
partitionOf:(__ create_table_partition_of_clause)?
ofType:(__ create_table_of_type_clause)?
columns:(__ paren$list$create_definition)?
columns:(__ (paren$list$create_definition / x:paren$empty_list &postgres { return x; }))?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we actually don't even need to limit this to only Postgres. I cannot really foresee any harm in supporting it for all dialects.

This parser is not designed to be a validator. So it often accepts SQL that's might not be legal in some dialect, if it just keeps the parser code simpler and doesn't break anything.

Anyway... that's just FYI. Not expecting anything from you regarding this.

options:(__ table_options)?
clauses:(__ create_table_clause)*
{
Expand Down
16 changes: 15 additions & 1 deletion test/ddl/create_table.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dialect, testWc } from "../test_utils";
import { dialect, notDialect, test, testWc } from "../test_utils";

describe("create table", () => {
it("supports simple CREATE TABLE statement", () => {
Expand Down Expand Up @@ -40,6 +40,20 @@ describe("create table", () => {
});
});

dialect(["postgresql", "plpgsql"], () => {
it("supports table with zero columns", () => {
testWc("CREATE TABLE foo ()");
testWc("CREATE TABLE foo ( )");
Comment on lines +45 to +46

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit too many tests in here for my taste. The second case is the important one and also covers the first.

testWc("CREATE TABLE foo () INHERITS (bar)");
});
});

notDialect(["postgresql", "plpgsql"], () => {
it("does not support table with zero columns", () => {
expect(() => test("CREATE TABLE foo ()")).toThrow();
});
});

it("supports IF NOT EXISTS", () => {
testWc("CREATE TABLE IF NOT EXISTS foo (id INT)");
});
Expand Down
Loading