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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tyler Brock <tyler(dot)brock(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: DataRow message for Integer(int4) returns result as text?
Date: 2022-04-21 03:09:19
Message-ID: 3078175.1650510559@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tyler Brock <tyler(dot)brock(at)gmail(dot)com> writes:
> 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).

If you mean the "data type size" (typlen) field of RowDescription, that
is arguably completely irrelevant; it's there for historical reasons,
I think. The contents of a DataRow field will either be a textual
conversion of the value or the on-the-wire binary representation defined
by the type's typsend routine. In either case, the actual length of
the value as it appears in DataRow is given right there in the DataRow
message. And in either case, the typlen value doesn't necessarily have
anything to do with the length of the DataRow representation. typlen
does happen to match up with the length that'd appear in DataRow for
simple integral types sent in binary format ... but for other cases,
not so much.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2022-04-21 03:15:07 Re: Skipping schema changes in publication
Previous Message wangw.fnst@fujitsu.com 2022-04-21 03:05:13 RE: Data is copied twice when specifying both child and parent table in publication