@@ -1477,6 +1477,22 @@ impl fmt::Display for TableIndexDirective {
14771477 }
14781478}
14791479
1480+ /// PostgreSQL table inheritance marker, see [`TableFactor::Table::inheritance`].
1481+ ///
1482+ /// <https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM>
1483+ #[ derive( Debug , Copy , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1484+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1485+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1486+ pub enum TableInheritance {
1487+ /// `ONLY name`, or `ONLY (name)` when `parenthesized`, excluding descendant tables.
1488+ Only {
1489+ /// Whether the name was written in parentheses.
1490+ parenthesized : bool ,
1491+ } ,
1492+ /// `name *`, explicitly including descendant tables.
1493+ IncludeDescendants ,
1494+ }
1495+
14801496/// A table name or a parenthesized subquery with an optional alias
14811497#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
14821498#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -1516,6 +1532,8 @@ pub enum TableFactor {
15161532 sample : Option < TableSampleKind > ,
15171533 /// Optional table-level index-selection hints or requirements.
15181534 index_directives : Vec < TableIndexDirective > ,
1535+ /// PostgreSQL `ONLY` or `*` inheritance marker.
1536+ inheritance : Option < TableInheritance > ,
15191537 } ,
15201538 /// A derived table (a parenthesized subquery), optionally `LATERAL`.
15211539 Derived {
@@ -2250,8 +2268,18 @@ impl fmt::Display for TableFactor {
22502268 json_path,
22512269 sample,
22522270 index_directives,
2271+ inheritance,
22532272 } => {
2254- name. fmt ( f) ?;
2273+ match inheritance {
2274+ Some ( TableInheritance :: Only {
2275+ parenthesized : true ,
2276+ } ) => write ! ( f, "ONLY ({name})" ) ?,
2277+ Some ( TableInheritance :: Only {
2278+ parenthesized : false ,
2279+ } ) => write ! ( f, "ONLY {name}" ) ?,
2280+ Some ( TableInheritance :: IncludeDescendants ) => write ! ( f, "{name} *" ) ?,
2281+ None => name. fmt ( f) ?,
2282+ }
22552283 if let Some ( json_path) = json_path {
22562284 json_path. fmt ( f) ?;
22572285 }
0 commit comments