diff --git a/src/ast/dcl.rs b/src/ast/dcl.rs index 3c50a81c0..830fdb2c7 100644 --- a/src/ast/dcl.rs +++ b/src/ast/dcl.rs @@ -463,12 +463,13 @@ impl fmt::Display for Grant { write!(f, " ON {objects}")?; } write!(f, " TO {}", display_comma_separated(&self.grantees))?; - if let Some(ref current_grants) = self.current_grants { - write!(f, " {current_grants}")?; - } + // Printed in the order the parser reads them, so the output re-parses. if self.with_grant_option { write!(f, " WITH GRANT OPTION")?; } + if let Some(ref current_grants) = self.current_grants { + write!(f, " {current_grants}")?; + } if let Some(ref as_grantor) = self.as_grantor { write!(f, " AS {as_grantor}")?; } diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index bad083602..57871052e 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -10042,6 +10042,10 @@ fn parse_grant() { verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST"); verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST COPY CURRENT GRANTS"); verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST REVOKE CURRENT GRANTS"); + // Printing these the other way round yields output the parser rejects. + verified_stmt( + "GRANT OWNERSHIP ON ALL TABLES IN SCHEMA s TO ROLE r WITH GRANT OPTION COPY CURRENT GRANTS", + ); verified_stmt("GRANT USAGE ON DATABASE db1 TO ROLE role1"); verified_stmt("GRANT USAGE ON WAREHOUSE wh1 TO ROLE role1"); verified_stmt("GRANT OWNERSHIP ON INTEGRATION int1 TO ROLE role1");