Added support for CREATE DOMAIN (#1830)

This commit is contained in:
Luca Cappelletti 2025-05-04 23:21:44 +02:00 committed by GitHub
parent a497358c3a
commit ac1c339666
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 183 additions and 6 deletions

View file

@ -4625,6 +4625,8 @@ impl<'a> Parser<'a> {
self.parse_create_external_table(or_replace)
} else if self.parse_keyword(Keyword::FUNCTION) {
self.parse_create_function(or_alter, or_replace, temporary)
} else if self.parse_keyword(Keyword::DOMAIN) {
self.parse_create_domain()
} else if self.parse_keyword(Keyword::TRIGGER) {
self.parse_create_trigger(or_alter, or_replace, false)
} else if self.parse_keywords(&[Keyword::CONSTRAINT, Keyword::TRIGGER]) {
@ -5974,6 +5976,35 @@ impl<'a> Parser<'a> {
Ok(owner)
}
/// Parses a [Statement::CreateDomain] statement.
fn parse_create_domain(&mut self) -> Result<Statement, ParserError> {
let name = self.parse_object_name(false)?;
self.expect_keyword_is(Keyword::AS)?;
let data_type = self.parse_data_type()?;
let collation = if self.parse_keyword(Keyword::COLLATE) {
Some(self.parse_identifier()?)
} else {
None
};
let default = if self.parse_keyword(Keyword::DEFAULT) {
Some(self.parse_expr()?)
} else {
None
};
let mut constraints = Vec::new();
while let Some(constraint) = self.parse_optional_table_constraint()? {
constraints.push(constraint);
}
Ok(Statement::CreateDomain(CreateDomain {
name,
data_type,
collation,
default,
constraints,
}))
}
/// ```sql
/// CREATE POLICY name ON table_name [ AS { PERMISSIVE | RESTRICTIVE } ]
/// [ FOR { ALL | SELECT | INSERT | UPDATE | DELETE } ]