Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for pg ADD GENERATED in ALTER COLUMN statements #1079

Merged
merged 2 commits into from
Jan 2, 2024

Conversation

tobyhede
Copy link
Contributor

@tobyhede tobyhede commented Jan 1, 2024

ADD GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]

Includes the identity/sequence options

ALTER TABLE t ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY
ALTER TABLE t ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY
ALTER TABLE t ALTER COLUMN id ADD GENERATED AS IDENTITY
ALTER TABLE t ALTER COLUMN id ADD GENERATED AS IDENTITY ( INCREMENT 1 MINVALUE 1 )
ALTER TABLE t ALTER COLUMN id ADD GENERATED AS IDENTITY ( )

Fixes #988

@tobyhede tobyhede force-pushed the pg-add-generated branch 4 times, most recently from 7a34cd5 to c687df4 Compare January 1, 2024 04:11
@tobyhede
Copy link
Contributor Author

tobyhede commented Jan 1, 2024

@alamb Working on the broken test ... not happening locally.

Signed-off-by: Toby Hede <toby@cipherstash.com>
@tobyhede
Copy link
Contributor Author

tobyhede commented Jan 1, 2024

Actually. PEBKAC. As always 🤦

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution @tobyhede -- this looks almost good to me with the exception of some of the error handling, as I have pointed out above

None
};

let _ = self.expect_keywords(&[Keyword::AS, Keyword::IDENTITY]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this ignoring the result? shouldn't it at least check and return the error, like:

Suggested change
let _ = self.expect_keywords(&[Keyword::AS, Keyword::IDENTITY]);
self.expect_keywords(&[Keyword::AS, Keyword::IDENTITY])?;


if self.peek_token().token == Token::LParen {
self.expect_token(&Token::LParen)?;
sequence_options = self.parse_create_sequence_options().ok();
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise here, I don't understand why the error is ignored. If there is a reason maybe we can add a comment.

I also wonder if we are sure that if parse_create_sequence_options returns an error that it hasn't consumed any tokens

);

pg_and_generic().verified_stmt("ALTER TABLE t ALTER COLUMN id ADD GENERATED AS IDENTITY ( )");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Given there is some seemingly non trival error handling, can you please add some tests that hit the errors (e.g. when the two statements I identified above actually return an error?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On it

Signed-off-by: Toby Hede <toby@cipherstash.com>
@coveralls
Copy link

coveralls commented Jan 1, 2024

Pull Request Test Coverage Report for Build 7380471401

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 87.821%

Totals Coverage Status
Change from base Build 7378974912: 0.001%
Covered Lines: 18697
Relevant Lines: 21290

💛 - Coveralls

@tobyhede
Copy link
Contributor Author

tobyhede commented Jan 1, 2024

@alamb Added the missed errors, and added tests to cover the cases. Sorry for missing such basics.

@alamb
Copy link
Contributor

alamb commented Jan 2, 2024

@alamb Added the missed errors, and added tests to cover the cases. Sorry for missing such basics.

No worries at all -- thank you for your continued contributions!

@alamb alamb merged commit 1d63466 into apache:main Jan 2, 2024
10 checks passed
@tobyhede tobyhede deleted the pg-add-generated branch August 27, 2024 05:09
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.

Cannot parse ADD GENERATED
3 participants