Skip to content

Added SORTKEY keyword parsing for redshift queries#2261

Merged
iffyio merged 3 commits intoapache:mainfrom
romanoff:fix_sortkey_for_redshift
Mar 5, 2026
Merged

Added SORTKEY keyword parsing for redshift queries#2261
iffyio merged 3 commits intoapache:mainfrom
romanoff:fix_sortkey_for_redshift

Conversation

@romanoff
Copy link
Contributor

@romanoff romanoff commented Mar 4, 2026

Added SORTKEY keyword parsing for redshift queries

Example of query:

CREATE TABLE users (
    user_id BIGINT,
    email VARCHAR(255),
    created_at TIMESTAMP
)
SORTKEY (created_at);

Spec:
https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html
https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_AS.html
https://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_TABLE.html

column_position,
}
} else if self.parse_keyword(Keyword::ALTER) {
// Redshift: ALTER SORTKEY (column_list)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Redshift: ALTER SORTKEY (column_list)

Comment on lines +10270 to +10275
if self.parse_keyword(Keyword::SORTKEY) {
self.expect_token(&Token::LParen)?;
let columns = self.parse_comma_separated(|p| p.parse_expr())?;
self.expect_token(&Token::RParen)?;
return Ok(AlterTableOperation::AlterSortKey { columns });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we pull this out to its own function (the block is already quite big)? we can do something like the following here to make the function self contained

if self.peek(TOKEN::SORT_KEY) {
    self.prev_token(); // Put back the `ALTER` keyword
    return self.parse_alter_sort_key() 
}

@romanoff romanoff force-pushed the fix_sortkey_for_redshift branch from a455ed6 to d5dd088 Compare March 4, 2026 21:47
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @romanoff!

@iffyio iffyio added this pull request to the merge queue Mar 5, 2026
Merged via the queue into apache:main with commit 64f4b1f Mar 5, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants