Skip to content
Open
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
1 change: 1 addition & 0 deletions fuzz/fuzz_seeds/postgresql_3039_table_statement.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TABLE t;
17 changes: 15 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,11 @@ impl<'a> Parser<'a> {
self.prev_token();
self.parse_raise_stmt().map(Into::into)
}
Keyword::SELECT | Keyword::WITH | Keyword::VALUES | Keyword::FROM => {
Keyword::SELECT
| Keyword::WITH
| Keyword::VALUES
| Keyword::FROM
| Keyword::TABLE => {
self.prev_token();
self.parse_query().map(Into::into)
}
Expand Down Expand Up @@ -15848,7 +15852,16 @@ impl<'a> Parser<'a> {
}
}

match self.maybe_parse(|parser| parser.parse_statement())? {
// In dialects where `DESCRIBE TABLE t` describes a table, `TABLE` here
// starts the table name, not a `TABLE t` query.
let statement = if self.dialect.describe_requires_table_keyword()
&& self.peek_keyword(Keyword::TABLE)
{
None
} else {
self.maybe_parse(|parser| parser.parse_statement())?
};
match statement {
Some(Statement::Explain { .. }) | Some(Statement::ExplainTable { .. }) => Err(
ParserError::ParserError("Explain must be root of the plan".to_string()),
),
Expand Down
16 changes: 16 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23765,3 +23765,19 @@ fn parse_try_cast_shortcut() {
dialects.one_statement_parses_to("SELECT ? ::INT", "SELECT ?::INT");
dialects.verified_stmt("SELECT v:items[0].price?::DECIMAL(10,2)");
}

#[test]
fn parse_table_statement() {
let query = all_dialects().verified_query("TABLE t");
assert_eq!(
*query.body,
SetExpr::Table(Box::new(Table {
table_name: Some(Ident::new("t")),
schema_name: None,
}))
);
all_dialects().verified_stmt("TABLE s.t");
all_dialects().verified_stmt("TABLE t ORDER BY a LIMIT 1");
all_dialects().verified_stmt("TABLE t UNION ALL TABLE u");
all_dialects().one_statement_parses_to("(TABLE t)", "(TABLE t)");
}
10 changes: 10 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14597,3 +14597,13 @@ fn parse_alter_column_set_storage() {
);
}
}

#[test]
fn parse_explain_table_query() {
match pg().verified_stmt("EXPLAIN TABLE t") {
Statement::Explain { statement, .. } => {
assert_eq!(statement.to_string(), "TABLE t");
}
_ => panic!("Unexpected Statement, must be Explain"),
}
}
Loading