From 2ee726d37fbaaf8244574bd0c0f8f1c1e9226046 Mon Sep 17 00:00:00 2001 From: LucaCappelletti94 Date: Thu, 30 Jul 2026 20:26:12 +0200 Subject: [PATCH] Print GRANT clauses in the order the parser reads them --- src/ast/dcl.rs | 7 ++++--- tests/sqlparser_common.rs | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ast/dcl.rs b/src/ast/dcl.rs index 3c50a81c06..830fdb2c76 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 bad0836029..57871052ea 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");