feat: Add WITH OFFSET Alias (#528)

* feat: Add WITH OFFSET Alias

* update: fix with_offset_alias type
This commit is contained in:
sivchari 2022-06-30 02:29:44 +09:00 committed by GitHub
parent 17c238bda7
commit 68768530cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 2 deletions

View file

@ -367,6 +367,7 @@ pub enum TableFactor {
alias: Option<TableAlias>,
array_expr: Box<Expr>,
with_offset: bool,
with_offset_alias: Option<Ident>,
},
/// Represents a parenthesized table factor. The SQL spec only allows a
/// join expression (`(foo <JOIN> bar [ <JOIN> baz ... ])`) to be nested,
@ -423,6 +424,7 @@ impl fmt::Display for TableFactor {
alias,
array_expr,
with_offset,
with_offset_alias,
} => {
write!(f, "UNNEST({})", array_expr)?;
if let Some(alias) = alias {
@ -431,6 +433,9 @@ impl fmt::Display for TableFactor {
if *with_offset {
write!(f, " WITH OFFSET")?;
}
if let Some(alias) = with_offset_alias {
write!(f, " AS {}", alias)?;
}
Ok(())
}
TableFactor::NestedJoin(table_reference) => write!(f, "({})", table_reference),

View file

@ -3842,10 +3842,18 @@ impl<'a> Parser<'a> {
Err(_) => false,
};
let with_offset_alias =
match self.parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS) {
Ok(Some(alias)) => Some(alias),
Ok(None) => None,
Err(e) => return Err(e),
};
Ok(TableFactor::UNNEST {
alias,
array_expr: Box::new(expr),
with_offset,
with_offset_alias,
})
} else {
let name = self.parse_object_name()?;