From ec75e33fedc0132c594ef68df1ee3fbf3a5b0404 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Tue, 6 Oct 2026 21:53:58 -0500 Subject: [PATCH] Support zero-column CREATE TABLE in PostgreSQL --- src/parser.pegjs | 2 +- test/ddl/create_table.test.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/parser.pegjs b/src/parser.pegjs index 04376e9f..99a8a68f 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -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; }))? options:(__ table_options)? clauses:(__ create_table_clause)* { diff --git a/test/ddl/create_table.test.ts b/test/ddl/create_table.test.ts index 1b6a32dd..70c52537 100644 --- a/test/ddl/create_table.test.ts +++ b/test/ddl/create_table.test.ts @@ -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", () => { @@ -40,6 +40,20 @@ describe("create table", () => { }); }); + dialect(["postgresql", "plpgsql"], () => { + it("supports table with zero columns", () => { + testWc("CREATE TABLE foo ()"); + testWc("CREATE TABLE foo ( )"); + 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)"); });