Re: DataRow message for Integer(int4) returns result as text?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tyler Brock <tyler(dot)brock(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: DataRow message for Integer(int4) returns result as text?
Date: 2022-04-21 00:00:18
Message-ID: CAKFQuwYbhCmAJhxg42s+dtw72PgHN=Quj81xXWWMkMaZNhxnBA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Apr 20, 2022 at 4:39 PM Tyler Brock <tyler(dot)brock(at)gmail(dot)com> wrote:

> I think this makes sense but I wanted to get confirmation:
>
> I created a table with a column having the type int4 (integer). When I
> insert a row with a number into that column and get it back out I've
> observed a discrepancy:
>
> The DataRow message has the field encoded as an ASCII ‘7’ with a column
> length of 1 despite the RowDescription having a column length 4. I assume
> that this is because it’s a simple query (Q) and therefore the format code
> for all columns is 0 (for text format).
>
> It makes sense that at the time the RowDescription is written out that it
> can’t possibly know how many bytes the textual representation of each int
> will take so it just uses the length of the underlying type.
>
> Is this accurate?
>
>
You probably shouldn't think of DataRow as giving you a "column length" -
it is simply giving you the number of bytes you need to read to retrieve
all of the bytes for the column and thus position your read pointer at the
data length Int32 for the subsequent column (which you do iteratively Int16
column count times).

You now have bytes for columnN - which you need to interpret via
RowDescription to transform the raw protocol bytes into a meaningful datum.

You don't care whether the source API was simple or not - RowDescription
will tell you what you need to know to interpret the value - it is all
self-contained. But yes, because it is a simple query the RowDescription
meta-data will inform you that all of the bytes represent (in aggregate ?)
the textual representation of the data.

David J.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tyler Brock 2022-04-21 00:11:47 Re: DataRow message for Integer(int4) returns result as text?
Previous Message David G. Johnston 2022-04-20 23:40:44 doc: New cumulative stats subsystem obsoletes comment in maintenance.sgml