Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 612d27d

Browse files
kelvichJakub Wieczorek
authored and
Jakub Wieczorek
committed
Return more RowDescription fields
As we are trying to match client-side behaviour with node-postgres we need to return this fields as well because node-postgres returns them.
1 parent b892e49 commit 612d27d

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

tokio-postgres/src/client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,10 @@ impl Client {
439439
if let Some(row_description) = row_description {
440440
let mut it = row_description.fields();
441441
while let Some(field) = it.next().map_err(Error::parse)? {
442+
// NB: for some types that function may send a query to the server. At least in
443+
// raw text mode we don't need that info and can skip this.
442444
let type_ = get_type(&self.inner, field.type_oid()).await?;
443-
let column = Column::new(field.name().to_string(), type_);
445+
let column = Column::new(field.name().to_string(), type_, field);
444446
columns.push(column);
445447
}
446448
}

tokio-postgres/src/statement.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use crate::client::InnerClient;
22
use crate::codec::FrontendMessage;
33
use crate::connection::RequestMessages;
44
use crate::types::Type;
5-
use postgres_protocol::message::frontend;
5+
use postgres_protocol::{
6+
message::{backend::Field, frontend},
7+
Oid,
8+
};
69
use postgres_types::Format;
710
use std::{
811
fmt,

tokio-postgres/tests/test/main.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,31 @@ async fn command_tag() {
351351
assert_eq!(row_stream.command_tag(), Some("SELECT 3".to_string()));
352352
}
353353

354+
#[tokio::test]
355+
async fn column_extras() {
356+
let client = connect("user=postgres").await;
357+
358+
let rows: Vec<tokio_postgres::Row> = client
359+
.query_raw_txt("select relacl, relname from pg_class limit 1", [])
360+
.await
361+
.unwrap()
362+
.try_collect()
363+
.await
364+
.unwrap();
365+
366+
let column = rows[0].columns().get(1).unwrap();
367+
assert_eq!(column.name(), "relname");
368+
assert_eq!(column.type_(), &Type::NAME);
369+
370+
assert!(column.table_oid() > 0);
371+
assert_eq!(column.column_id(), 2);
372+
assert_eq!(column.format(), 0);
373+
374+
assert_eq!(column.type_oid(), 19);
375+
assert_eq!(column.type_size(), 64);
376+
assert_eq!(column.type_modifier(), -1);
377+
}
378+
354379
#[tokio::test]
355380
async fn custom_composite() {
356381
let client = connect("user=postgres").await;

0 commit comments

Comments
 (0)