Use Option<Expr> for Min and Max vals in Seq Opts, fix alter col seq display (#1106)

This commit is contained in:
Quinn Sinclair 2024-01-25 13:12:34 +01:00 committed by GitHub
parent 1b6b6aa65f
commit f5e27366f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 38 deletions

View file

@ -355,17 +355,13 @@ impl fmt::Display for AlterColumnOperation {
write!(f, "ADD GENERATED{generated_as} AS IDENTITY",)?;
if let Some(options) = sequence_options {
if !options.is_empty() {
write!(f, " (")?;
}
write!(f, " (")?;
for sequence_option in options {
write!(f, "{sequence_option}")?;
}
if !options.is_empty() {
write!(f, " )")?;
}
write!(f, " )")?;
}
Ok(())
}

View file

@ -3835,8 +3835,8 @@ impl fmt::Display for Statement {
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum SequenceOptions {
IncrementBy(Expr, bool),
MinValue(MinMaxValue),
MaxValue(MinMaxValue),
MinValue(Option<Expr>),
MaxValue(Option<Expr>),
StartWith(Expr, bool),
Cache(Expr),
Cycle(bool),
@ -3853,28 +3853,18 @@ impl fmt::Display for SequenceOptions {
increment = increment
)
}
SequenceOptions::MinValue(value) => match value {
MinMaxValue::Empty => {
write!(f, "")
}
MinMaxValue::None => {
write!(f, " NO MINVALUE")
}
MinMaxValue::Some(minvalue) => {
write!(f, " MINVALUE {minvalue}")
}
},
SequenceOptions::MaxValue(value) => match value {
MinMaxValue::Empty => {
write!(f, "")
}
MinMaxValue::None => {
write!(f, " NO MAXVALUE")
}
MinMaxValue::Some(maxvalue) => {
write!(f, " MAXVALUE {maxvalue}")
}
},
SequenceOptions::MinValue(Some(expr)) => {
write!(f, " MINVALUE {expr}")
}
SequenceOptions::MinValue(None) => {
write!(f, " NO MINVALUE")
}
SequenceOptions::MaxValue(Some(expr)) => {
write!(f, " MAXVALUE {expr}")
}
SequenceOptions::MaxValue(None) => {
write!(f, " NO MAXVALUE")
}
SequenceOptions::StartWith(start, with) => {
write!(
f,

View file

@ -8805,24 +8805,21 @@ impl<'a> Parser<'a> {
}
//[ MINVALUE minvalue | NO MINVALUE ]
if self.parse_keyword(Keyword::MINVALUE) {
sequence_options.push(SequenceOptions::MinValue(MinMaxValue::Some(Expr::Value(
sequence_options.push(SequenceOptions::MinValue(Some(Expr::Value(
self.parse_number_value()?,
))));
} else if self.parse_keywords(&[Keyword::NO, Keyword::MINVALUE]) {
sequence_options.push(SequenceOptions::MinValue(MinMaxValue::None));
} else {
sequence_options.push(SequenceOptions::MinValue(MinMaxValue::Empty));
sequence_options.push(SequenceOptions::MinValue(None));
}
//[ MAXVALUE maxvalue | NO MAXVALUE ]
if self.parse_keywords(&[Keyword::MAXVALUE]) {
sequence_options.push(SequenceOptions::MaxValue(MinMaxValue::Some(Expr::Value(
sequence_options.push(SequenceOptions::MaxValue(Some(Expr::Value(
self.parse_number_value()?,
))));
} else if self.parse_keywords(&[Keyword::NO, Keyword::MAXVALUE]) {
sequence_options.push(SequenceOptions::MaxValue(MinMaxValue::None));
} else {
sequence_options.push(SequenceOptions::MaxValue(MinMaxValue::Empty));
sequence_options.push(SequenceOptions::MaxValue(None));
}
//[ START [ WITH ] start ]
if self.parse_keywords(&[Keyword::START]) {
if self.parse_keywords(&[Keyword::WITH]) {