diff --git a/tokio-postgres/src/prepare.rs b/tokio-postgres/src/prepare.rs index e3f09a7c2..08b61c17d 100644 --- a/tokio-postgres/src/prepare.rs +++ b/tokio-postgres/src/prepare.rs @@ -95,7 +95,12 @@ pub async fn prepare( let mut it = row_description.fields(); while let Some(field) = it.next().map_err(Error::parse)? { let type_ = get_type(client, field.type_oid()).await?; - let column = Column::new(field.name().to_string(), type_); + let column = Column::new( + field.name().to_string(), + type_, + Some(field.table_oid()).filter(|oid| *oid != 0), + Some(field.column_id()).filter(|id| *id != 0), + ); columns.push(column); } } diff --git a/tokio-postgres/src/statement.rs b/tokio-postgres/src/statement.rs index 97561a8e4..0a5a6a3ed 100644 --- a/tokio-postgres/src/statement.rs +++ b/tokio-postgres/src/statement.rs @@ -68,11 +68,23 @@ impl Statement { pub struct Column { name: String, type_: Type, + table_oid: Option, + column_id: Option, } impl Column { - pub(crate) fn new(name: String, type_: Type) -> Column { - Column { name, type_ } + pub(crate) fn new( + name: String, + type_: Type, + table_oid: Option, + column_id: Option, + ) -> Column { + Column { + name, + type_, + table_oid, + column_id, + } } /// Returns the name of the column. @@ -84,6 +96,17 @@ impl Column { pub fn type_(&self) -> &Type { &self.type_ } + + /// Returns the oid of the column's table, if it is a direct alias to a column in a table + pub fn table_oid(&self) -> Option { + self.table_oid + } + + /// Returns the column's attribute number in its table, if it is a direct alias to a column in a + /// table + pub fn column_id(&self) -> Option { + self.column_id + } } impl fmt::Debug for Column {