mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-02 21:22:15 +00:00
Add support for Postgres ALTER TYPE
(#1727)
This commit is contained in:
parent
68c41a9d5a
commit
c75a992621
6 changed files with 271 additions and 61 deletions
|
@ -28,7 +28,6 @@
|
|||
// limitations under the License.
|
||||
use log::debug;
|
||||
|
||||
use crate::ast::{ObjectName, Statement, UserDefinedTypeRepresentation};
|
||||
use crate::dialect::{Dialect, Precedence};
|
||||
use crate::keywords::Keyword;
|
||||
use crate::parser::{Parser, ParserError};
|
||||
|
@ -135,15 +134,6 @@ impl Dialect for PostgreSqlDialect {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
|
||||
if parser.parse_keyword(Keyword::CREATE) {
|
||||
parser.prev_token(); // unconsume the CREATE in case we don't end up parsing anything
|
||||
parse_create(parser)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn supports_filter_during_aggregation(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
@ -259,37 +249,3 @@ impl Dialect for PostgreSqlDialect {
|
|||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_create(parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
|
||||
let name = parser.maybe_parse(|parser| -> Result<ObjectName, ParserError> {
|
||||
parser.expect_keyword_is(Keyword::CREATE)?;
|
||||
parser.expect_keyword_is(Keyword::TYPE)?;
|
||||
let name = parser.parse_object_name(false)?;
|
||||
parser.expect_keyword_is(Keyword::AS)?;
|
||||
parser.expect_keyword_is(Keyword::ENUM)?;
|
||||
Ok(name)
|
||||
});
|
||||
|
||||
match name {
|
||||
Ok(name) => name.map(|name| parse_create_type_as_enum(parser, name)),
|
||||
Err(e) => Some(Err(e)),
|
||||
}
|
||||
}
|
||||
|
||||
// https://www.postgresql.org/docs/current/sql-createtype.html
|
||||
pub fn parse_create_type_as_enum(
|
||||
parser: &mut Parser,
|
||||
name: ObjectName,
|
||||
) -> Result<Statement, ParserError> {
|
||||
if !parser.consume_token(&Token::LParen) {
|
||||
return parser.expected("'(' after CREATE TYPE AS ENUM", parser.peek_token());
|
||||
}
|
||||
|
||||
let labels = parser.parse_comma_separated0(|p| p.parse_identifier(), Token::RParen)?;
|
||||
parser.expect_token(&Token::RParen)?;
|
||||
|
||||
Ok(Statement::CreateType {
|
||||
name,
|
||||
representation: UserDefinedTypeRepresentation::Enum { labels },
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue