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

Implements ALTER POLICY syntax for PostgreSQL #1446

Merged
merged 7 commits into from
Sep 29, 2024

Conversation

git-hulk
Copy link
Member

ALTER POLICY name ON table_name RENAME TO new_name

ALTER POLICY name ON table_name
    [ TO { role_name | PUBLIC | CURRENT_ROLE | CURRENT_USER | SESSION_USER } [, ...] ]
    [ USING ( using_expression ) ]
    [ WITH CHECK ( check_expression ) ]

For the documentation, please refer:

https://www.postgresql.org/docs/current/sql-alterpolicy.html

```sql
ALTER POLICY name ON table_name RENAME TO new_name

ALTER POLICY name ON table_name
    [ TO { role_name | PUBLIC | CURRENT_ROLE | CURRENT_USER | SESSION_USER } [, ...] ]
    [ USING ( using_expression ) ]
    [ WITH CHECK ( check_expression ) ]
```

For the documentation, please refer:

https://www.postgresql.org/docs/current/sql-alterpolicy.html
@git-hulk git-hulk force-pushed the feature/alter-policy-for-pg branch from 753df07 to 5232492 Compare September 28, 2024 14:13
@coveralls
Copy link

coveralls commented Sep 28, 2024

Pull Request Test Coverage Report for Build 11091759958

Details

  • 76 of 90 (84.44%) changed or added relevant lines in 5 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.01%) to 89.31%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/ast/ddl.rs 14 16 87.5%
src/ast/mod.rs 4 6 66.67%
tests/sqlparser_common.rs 24 34 70.59%
Files with Coverage Reduction New Missed Lines %
src/ast/mod.rs 1 82.39%
src/parser/mod.rs 1 93.35%
Totals Coverage Status
Change from base Build 11091694888: -0.01%
Covered Lines: 29901
Relevant Lines: 33480

💛 - Coveralls

@git-hulk
Copy link
Member Author

cc @iffyio

Comment on lines 58 to 64
let to = if self.parse_keyword(Keyword::TO) {
Some(self.parse_comma_separated(|p| p.parse_owner())?)
} else {
None
};

if self.parse_keyword(Keyword::RENAME) {
Copy link
Contributor

Choose a reason for hiding this comment

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

from the doc it looks like the RENAME vs others are are mutually exclusive, so that if we parse a TO it probably won't be correct to potentially also parse a rename afterwards as the current code suggests?
e.g ALTER POLICY a on t TO owner RENAME TO new_name seems like its accepted by the parser?

Copy link
Member Author

@git-hulk git-hulk Sep 29, 2024

Choose a reason for hiding this comment

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

@iffyio Yes, you're right. I falsely parsed TO before REANME, will fix it soon. Thank you for your correction.

Copy link
Member Author

@git-hulk git-hulk Sep 29, 2024

Choose a reason for hiding this comment

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

@iffyio I have fixed this and added test cases to prevent it from happening. Pls refer: 69a1f36

@git-hulk git-hulk requested a review from iffyio September 29, 2024 06:22
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! cc @alamb

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.

Thanks @git-hulk -- there is a documentation tweak, but I'll make it and get this PR merged.

Thanks @iffyio for the review

src/ast/mod.rs Outdated Show resolved Hide resolved
@alamb
Copy link
Contributor

alamb commented Sep 29, 2024

I merged up from main to resolve a conflict

tests/sqlparser_common.rs Outdated Show resolved Hide resolved
@git-hulk
Copy link
Member Author

@alamb Thank you!

@alamb
Copy link
Contributor

alamb commented Sep 29, 2024

🚀

@alamb alamb merged commit 51cbd5a into apache:main Sep 29, 2024
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.

4 participants