Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions qusql-parse/src/alter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ pub struct IndexCol<'a> {
pub asc: Option<Span>,
/// Optional DESC ordering
pub desc: Option<Span>,
/// Optional NULLS FIRST / NULLS LAST ordering; bool is `true` if FIRST
pub nulls_first_last: Option<(bool, Span)>,
}

impl<'a> Spanned for IndexCol<'a> {
Expand All @@ -198,6 +200,7 @@ impl<'a> Spanned for IndexCol<'a> {
.join_span(&self.opclass)
.join_span(&self.asc)
.join_span(&self.desc)
.join_span(&self.nulls_first_last)
}
}

Expand Down Expand Up @@ -1709,6 +1712,7 @@ pub(crate) fn parse_index_cols<'a>(
opclass,
asc,
desc,
nulls_first_last: None,
});
if parser.skip_token(Token::Comma).is_none() {
break;
Expand Down
15 changes: 15 additions & 0 deletions qusql-parse/src/create_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,27 @@ pub(crate) fn parse_create_index<'a>(
None
};

// Parse optional NULLS FIRST | NULLS LAST
let nulls_first_last = if let Some(nulls_span) = parser.skip_keyword(Keyword::NULLS) {
if let Some(first_span) = parser.skip_keyword(Keyword::FIRST) {
Some((true, nulls_span.join_span(&first_span)))
} else if let Some(last_span) = parser.skip_keyword(Keyword::LAST) {
Some((false, nulls_span.join_span(&last_span)))
} else {
return parser.err_here("Expected FIRST or LAST after NULLS");
}
} else {
None
};
parser.postgres_only(&nulls_first_last);

column_names.push(IndexCol {
expr,
size,
opclass,
asc,
desc,
nulls_first_last,
});

if parser.skip_token(Token::Comma).is_none() {
Expand Down