Skip to content

Commit 1770cbc

Browse files
authored
PostgreSQL: rename Statement::Comment.relation to table_name (#31)
Aligns the partner-table field name with sibling AST nodes (AlterPolicy.table_name, CreatePolicy.table_name, DropPolicy.table_name, AlterTrigger.table_name). Breaking change on the public AST. Pure mechanical rename; no behavior change. Display impl, parser constructor, and existing COMMENT ON TRIGGER / POLICY / AGGREGATE / FUNCTION / COLLATION tests updated to match.
1 parent 621aa03 commit 1770cbc

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

src/ast/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4461,10 +4461,10 @@ pub enum Statement {
44614461
/// while `None` means no parameter list was provided. Used for
44624462
/// `FUNCTION`, `PROCEDURE`, and `AGGREGATE` targets.
44634463
arguments: Option<Vec<DataType>>,
4464-
/// Partner relation for objects scoped to a table, i.e. the
4465-
/// `ON <relation>` tail in `COMMENT ON TRIGGER t ON tbl IS '…'` or
4464+
/// Partner table for objects scoped to a table, i.e. the
4465+
/// `ON <table>` tail in `COMMENT ON TRIGGER t ON tbl IS '…'` or
44664466
/// `COMMENT ON POLICY p ON tbl IS '…'`.
4467-
relation: Option<ObjectName>,
4467+
table_name: Option<ObjectName>,
44684468
/// Optional comment text (None to remove comment).
44694469
comment: Option<String>,
44704470
/// An optional `IF EXISTS` clause. (Non-standard.)
@@ -6252,7 +6252,7 @@ impl fmt::Display for Statement {
62526252
object_type,
62536253
object_name,
62546254
arguments,
6255-
relation,
6255+
table_name,
62566256
comment,
62576257
if_exists,
62586258
} => {
@@ -6264,8 +6264,8 @@ impl fmt::Display for Statement {
62646264
if let Some(args) = arguments {
62656265
write!(f, "({})", display_comma_separated(args))?;
62666266
}
6267-
if let Some(relation) = relation {
6268-
write!(f, " ON {relation}")?;
6267+
if let Some(table_name) = table_name {
6268+
write!(f, " ON {table_name}")?;
62696269
}
62706270
write!(f, " IS ")?;
62716271
if let Some(c) = comment {

src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ impl<'a> Parser<'a> {
939939
));
940940
}
941941

942-
let relation = match object_type {
942+
let table_name = match object_type {
943943
CommentObject::Trigger | CommentObject::Policy => {
944944
self.expect_keyword_is(Keyword::ON)?;
945945
Some(self.parse_object_name(false)?)
@@ -957,7 +957,7 @@ impl<'a> Parser<'a> {
957957
object_type,
958958
object_name,
959959
arguments,
960-
relation,
960+
table_name,
961961
comment,
962962
if_exists,
963963
})

tests/sqlparser_postgres.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ fn parse_drop_and_comment_collation_ast() {
11151115
object_type: CommentObject::Collation,
11161116
object_name: ObjectName::from(vec![Ident::new("test0")]),
11171117
arguments: None,
1118-
relation: None,
1118+
table_name: None,
11191119
comment: Some("US English".to_string()),
11201120
if_exists: false,
11211121
}
@@ -10558,14 +10558,14 @@ fn parse_comment_on_trigger() {
1055810558
Statement::Comment {
1055910559
object_type,
1056010560
object_name,
10561-
relation,
10561+
table_name,
1056210562
arguments,
1056310563
comment,
1056410564
if_exists,
1056510565
} => {
1056610566
assert_eq!(CommentObject::Trigger, object_type);
1056710567
assert_eq!("my_trigger", object_name.to_string());
10568-
assert_eq!("public.my_table", relation.unwrap().to_string());
10568+
assert_eq!("public.my_table", table_name.unwrap().to_string());
1056910569
assert!(arguments.is_none());
1057010570
assert_eq!(Some("trigger note".to_string()), comment);
1057110571
assert!(!if_exists);
@@ -10585,14 +10585,14 @@ fn parse_comment_on_policy() {
1058510585
Statement::Comment {
1058610586
object_type,
1058710587
object_name,
10588-
relation,
10588+
table_name,
1058910589
arguments,
1059010590
comment,
1059110591
if_exists,
1059210592
} => {
1059310593
assert_eq!(CommentObject::Policy, object_type);
1059410594
assert_eq!("tenant_isolation", object_name.to_string());
10595-
assert_eq!("public.docs", relation.unwrap().to_string());
10595+
assert_eq!("public.docs", table_name.unwrap().to_string());
1059610596
assert!(arguments.is_none());
1059710597
assert_eq!(Some("rls".to_string()), comment);
1059810598
assert!(!if_exists);
@@ -10609,14 +10609,14 @@ fn parse_comment_on_aggregate() {
1060910609
Statement::Comment {
1061010610
object_type,
1061110611
object_name,
10612-
relation,
10612+
table_name,
1061310613
arguments,
1061410614
comment,
1061510615
if_exists,
1061610616
} => {
1061710617
assert_eq!(CommentObject::Aggregate, object_type);
1061810618
assert_eq!("my_sum", object_name.to_string());
10619-
assert!(relation.is_none());
10619+
assert!(table_name.is_none());
1062010620
let args = arguments.expect("aggregate should carry argument types");
1062110621
assert_eq!(1, args.len());
1062210622
assert!(matches!(args[0], DataType::Integer(_)));
@@ -10646,14 +10646,14 @@ fn parse_comment_on_function_with_arg_types() {
1064610646
Statement::Comment {
1064710647
object_type,
1064810648
object_name,
10649-
relation,
10649+
table_name,
1065010650
arguments,
1065110651
comment,
1065210652
if_exists,
1065310653
} => {
1065410654
assert_eq!(CommentObject::Function, object_type);
1065510655
assert_eq!("add", object_name.to_string());
10656-
assert!(relation.is_none());
10656+
assert!(table_name.is_none());
1065710657
let args = arguments.expect("function should carry argument types");
1065810658
assert_eq!(2, args.len());
1065910659
assert_eq!(Some("adds".to_string()), comment);

0 commit comments

Comments
 (0)