Skip to content

Added SORTKEY keyword parsing for redshift queries#2261

Open
romanoff wants to merge 2 commits intoapache:mainfrom
romanoff:fix_sortkey_for_redshift
Open

Added SORTKEY keyword parsing for redshift queries#2261
romanoff wants to merge 2 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() 
}

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