fmguerreiro opened a new pull request, #2322:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2322
### What wasn't working
Postgres rejects these statements at parse time because the AST has no shape
for them — downstream consumers (e.g. pgmold) must strip them before calling
`Parser::parse_sql`:
- `ALTER TYPE foo OWNER TO some_role`
- `ALTER TYPE foo SET SCHEMA other_schema`
- `ALTER TYPE foo { ADD | DROP | ALTER | RENAME } ATTRIBUTE ...`
- `ALTER DEFAULT PRIVILEGES [FOR ROLE r] [IN SCHEMA s] { GRANT | REVOKE }
... ON { TABLES | SEQUENCES | FUNCTIONS | ROUTINES | TYPES | SCHEMAS } { TO |
FROM } ...`
`AlterTypeOperation` only had `Rename | AddValue | RenameValue`, and
`Statement::AlterDefaultPrivileges` did not exist.
### What changed
- `AlterTypeOperation` gains `OwnerTo`, `SetSchema`, `AddAttribute`,
`DropAttribute`, `AlterAttribute`, `RenameAttribute`. The Postgres grammar (`IF
[NOT] EXISTS`, `COLLATE`, `CASCADE | RESTRICT`) is honoured. `OwnerTo` reuses
`Owner` (same type as `AlterTableOperation::OwnerTo` /
`AlterCollationOperation::OwnerTo`).
- New `Statement::AlterDefaultPrivileges(AlterDefaultPrivileges)` carries
`for_roles: Vec<Ident>`, `in_schemas: Vec<Ident>`, and an
`AlterDefaultPrivilegesAction { Grant { ... } | Revoke { ... } }` body that
reuses the existing `Privileges` and `Grantee` types. The `ON <kind>` target
uses a new `AlterDefaultPrivilegesObjectType` enum.
- New keywords: `ATTRIBUTE`, `ROUTINES`, `TYPES`. `parse_alter` accepts
`DEFAULT` as a leading object token.
### Examples
```sql
ALTER TYPE public.my_type OWNER TO some_role
ALTER TYPE public.my_type SET SCHEMA other_schema
ALTER TYPE foo ADD ATTRIBUTE IF NOT EXISTS new_attr TEXT CASCADE
ALTER TYPE foo ALTER ATTRIBUTE attr SET DATA TYPE INTEGER
ALTER TYPE foo RENAME ATTRIBUTE old_attr TO new_attr
ALTER DEFAULT PRIVILEGES FOR ROLE app_role IN SCHEMA public, audit
GRANT SELECT, INSERT ON TABLES TO reader, writer WITH GRANT OPTION
ALTER DEFAULT PRIVILEGES IN SCHEMA public
REVOKE GRANT OPTION FOR ALL PRIVILEGES ON FUNCTIONS FROM reader CASCADE
```
### Breaking change disclosure
Both `AlterTypeOperation` and `Statement` are not `#[non_exhaustive]`.
Adding variants is technically a breaking change for downstream consumers that
match exhaustively without a `_` arm. Recommend cutting the next release as
`0.61.0`.
### Verified
```
cargo fmt --all
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features
cargo check --no-default-features --target thumbv6m-none-eabi
(cd sqlparser_bench && cargo clippy --all-targets --all-features -- -D
warnings)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]