Skip to content

Commit b3a2a6b

Browse files
committed
Support CREATE TABLE with no columns
This is weird, but supported by PostgreSQL.
1 parent 2308c1c commit b3a2a6b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/sqlparser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ impl Parser {
833833
fn parse_columns(&mut self) -> Result<(Vec<SQLColumnDef>, Vec<TableConstraint>), ParserError> {
834834
let mut columns = vec![];
835835
let mut constraints = vec![];
836-
if !self.consume_token(&Token::LParen) {
836+
if !self.consume_token(&Token::LParen) || self.consume_token(&Token::RParen) {
837837
return Ok((columns, constraints));
838838
}
839839

tests/sqlparser_common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,12 @@ fn parse_create_external_table() {
820820
}
821821
}
822822

823+
#[test]
824+
fn parse_create_table_empty() {
825+
// Zero-column tables are weird, but supported by at least PostgreSQL.
826+
let _ = verified_stmt("CREATE TABLE t ()");
827+
}
828+
823829
#[test]
824830
fn parse_alter_table_constraints() {
825831
check_one("CONSTRAINT address_pkey PRIMARY KEY (address_id)");

0 commit comments

Comments
 (0)