Skip to content

Added SORTKEY keyword parsing for redshift queries - #2261

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

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

Conversation

@romanoff

Copy link
Copy Markdown

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

Comment threadsrc/parser/mod.rs Outdated
column_position,
}
} else if self.parse_keyword(Keyword::ALTER) {
// Redshift: ALTER SORTKEY (column_list)

Copy link
Copy Markdown
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 threadsrc/parser/mod.rs Outdated
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
Copy Markdown
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
romanoffforce-pushed the fix_sortkey_for_redshift branch from a455ed6 to d5dd088CompareMarch 4, 2026 21:47

@iffyioiffyio left a comment

Copy link
Copy Markdown
Contributor

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 queueMar 5, 2026
Merged via the queue into apache:main with commit 64f4b1fMar 5, 2026
10 checks passed
Sign up for freeto 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

@romanoff@iffyio