Skip to content

Commit 183e083

Browse files
Print GRANT clauses in the order the parser reads them (#2415)
1 parent 777a166 commit 183e083

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/ast/dcl.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,13 @@ impl fmt::Display for Grant {
463463
write!(f, " ON {objects}")?;
464464
}
465465
write!(f, " TO {}", display_comma_separated(&self.grantees))?;
466-
if let Some(ref current_grants) = self.current_grants {
467-
write!(f, " {current_grants}")?;
468-
}
466+
// Printed in the order the parser reads them, so the output re-parses.
469467
if self.with_grant_option {
470468
write!(f, " WITH GRANT OPTION")?;
471469
}
470+
if let Some(ref current_grants) = self.current_grants {
471+
write!(f, " {current_grants}")?;
472+
}
472473
if let Some(ref as_grantor) = self.as_grantor {
473474
write!(f, " AS {as_grantor}")?;
474475
}

tests/sqlparser_common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10058,6 +10058,10 @@ fn parse_grant() {
1005810058
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST");
1005910059
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST COPY CURRENT GRANTS");
1006010060
verified_stmt("GRANT OWNERSHIP ON ALL TABLES IN SCHEMA DEV_STAS_ROGOZHIN TO ROLE ANALYST REVOKE CURRENT GRANTS");
10061+
// Printing these the other way round yields output the parser rejects.
10062+
verified_stmt(
10063+
"GRANT OWNERSHIP ON ALL TABLES IN SCHEMA s TO ROLE r WITH GRANT OPTION COPY CURRENT GRANTS",
10064+
);
1006110065
verified_stmt("GRANT USAGE ON DATABASE db1 TO ROLE role1");
1006210066
verified_stmt("GRANT USAGE ON WAREHOUSE wh1 TO ROLE role1");
1006310067
verified_stmt("GRANT OWNERSHIP ON INTEGRATION int1 TO ROLE role1");

0 commit comments

Comments
 (0)