-
Notifications
You must be signed in to change notification settings - Fork 782
PostgreSQL: Add support for TABLE query command #2512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -298,19 +298,30 @@ impl fmt::Display for SetQuantifier { | |||||
| /// A [`TABLE` command](https://www.postgresql.org/docs/current/sql-select.html#SQL-TABLE) | ||||||
| #[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] | ||||||
| pub struct Table { | ||||||
| /// `ONLY` modifier before the table name. | ||||||
| pub only: bool, | ||||||
| /// Optional table name (absent for e.g. `TABLE` command without argument). | ||||||
| pub table_name: Option<Ident>, | ||||||
| /// Optional schema/catalog name qualifying the table. | ||||||
| pub schema_name: Option<Ident>, | ||||||
| /// Trailing `*` modifier after the table name. | ||||||
| pub with_asterisk: bool, | ||||||
| } | ||||||
|
|
||||||
| impl fmt::Display for Table { | ||||||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||||
| if let Some(ref table_name) = self.table_name { | ||||||
| write!(f, "TABLE ")?; | ||||||
| if self.only { | ||||||
| write!(f, "ONLY ")?; | ||||||
| } | ||||||
| if let Some(ref schema_name) = self.schema_name { | ||||||
| write!(f, "TABLE {}.{}", schema_name, table_name,)?; | ||||||
| write!(f, "{}.{}", schema_name, table_name,)?; | ||||||
| } else { | ||||||
| write!(f, "TABLE {}", table_name)?; | ||||||
| write!(f, "{}", table_name)?; | ||||||
| } | ||||||
| if self.with_asterisk { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should follow the
Suggested change
|
||||||
| write!(f, " *")?; | ||||||
| } | ||||||
| } else { | ||||||
| write!(f, "TABLE")?; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -641,7 +641,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::TABLE | ||||||
| | Keyword::WITH | ||||||
| | Keyword::VALUES | ||||||
| | Keyword::FROM => { | ||||||
| self.prev_token(); | ||||||
| self.parse_query().map(Into::into) | ||||||
| } | ||||||
|
|
@@ -14496,7 +14500,15 @@ impl<'a> Parser<'a> { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| match self.maybe_parse(|parser| parser.parse_statement())? { | ||||||
| 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()), | ||||||
| ), | ||||||
|
|
@@ -15625,17 +15637,22 @@ impl<'a> Parser<'a> { | |||||
|
|
||||||
| /// Parse `CREATE TABLE x AS TABLE y` | ||||||
| pub fn parse_as_table(&mut self) -> Result<Table, ParserError> { | ||||||
| let only = self.parse_keyword(Keyword::ONLY); | ||||||
| let first_name = self.parse_identifier()?; | ||||||
| if self.consume_token(&Token::Period) { | ||||||
| let second_name = self.parse_identifier()?; | ||||||
| Ok(Table { | ||||||
| only, | ||||||
| table_name: Some(second_name), | ||||||
| schema_name: Some(first_name), | ||||||
| with_asterisk: self.consume_token(&Token::Mul), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should follow the
Suggested change
|
||||||
| }) | ||||||
| } else { | ||||||
| Ok(Table { | ||||||
| only, | ||||||
| table_name: Some(first_name), | ||||||
| schema_name: None, | ||||||
| with_asterisk: self.consume_token(&Token::Mul), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should follow the
Suggested change
|
||||||
| }) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should name this field
has_asteriskto follow pre-existing standard.