pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedlibpq: empty arrays have rank 0 in binary results? whatever the type's rank?
3+ messages / 2 participants
[nested] [flat]
* libpq: empty arrays have rank 0 in binary results? whatever the type's rank?
@ 2023-03-29 13:37 Dominique Devienne <ddevienne@gmail.com>
2023-03-29 13:45 ` Re: libpq: empty arrays have rank 0 in binary results? whatever the type's rank? Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Dominique Devienne @ 2023-03-29 13:37 UTC (permalink / raw)
To: pgsql-general
Hi. Selecting/fetching an empty 1D array using a binary-mode PGresult,
gives me back 12 bytes, and the first 4, the rank, is 0, something I was
not expecting.
I was expecting dims_rank = 1, then first_dim = 0
Normal? Next two ints are kinda useless given the 0 rank?
It's easy to fix, to support rank=0 for empty arrays, I just want to
confirm.
Thanks, --DD
PS: On a side note; where can I find the sending code for arrays?
I didn't find the usual _send() and _recv() functions (but looking on
github online...)
PPS: The relevant part of my code is below, for context:
uint32_t dims_rank = read();
if (dims_rank != 1) {
throw std::runtime_error(fmt::format(
"Unsupported array rank: Got {}; Want 1", dims_rank
));
}
uint32_t has_nulls = read();
uint32_t actual_elem_oid = read();
uint32_t first_dim = read();
uint32_t lower_idx = read();
ensure_oid(Oid{ actual_elem_oid }, expected_elem_oid);
UNUSED(has_nulls);
assert(lower_idx == 1);
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: libpq: empty arrays have rank 0 in binary results? whatever the type's rank?
2023-03-29 13:37 libpq: empty arrays have rank 0 in binary results? whatever the type's rank? Dominique Devienne <ddevienne@gmail.com>
@ 2023-03-29 13:45 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-03-29 14:02 ` Re: libpq: empty arrays have rank 0 in binary results? whatever the type's rank? Dominique Devienne <ddevienne@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2023-03-29 13:45 UTC (permalink / raw)
To: Dominique Devienne <ddevienne@gmail.com>; +Cc: pgsql-general
Dominique Devienne <ddevienne@gmail.com> writes:
> Hi. Selecting/fetching an empty 1D array using a binary-mode PGresult,
> gives me back 12 bytes, and the first 4, the rank, is 0, something I was
> not expecting.
Yeah, empty arrays have zero dimensions.
> PS: On a side note; where can I find the sending code for arrays?
> I didn't find the usual _send() and _recv() functions (but looking on
> github online...)
https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/adt/arrayfuncs.c;h=87...
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: libpq: empty arrays have rank 0 in binary results? whatever the type's rank?
2023-03-29 13:37 libpq: empty arrays have rank 0 in binary results? whatever the type's rank? Dominique Devienne <ddevienne@gmail.com>
2023-03-29 13:45 ` Re: libpq: empty arrays have rank 0 in binary results? whatever the type's rank? Tom Lane <tgl@sss.pgh.pa.us>
@ 2023-03-29 14:02 ` Dominique Devienne <ddevienne@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Dominique Devienne @ 2023-03-29 14:02 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general
On Wed, Mar 29, 2023 at 3:45 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Dominique Devienne <ddevienne@gmail.com> writes:
> > Hi. Selecting/fetching an empty 1D array using a binary-mode PGresult,
> > gives me back 12 bytes, and the first 4, the rank, is 0, something I was
> > not expecting.
>
> Yeah, empty arrays have zero dimensions.
>
> > PS: On a side note; where can I find the sending code for arrays?
> > I didn't find the usual _send() and _recv() functions (but looking on
> > github online...)
>
>
> https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/utils/adt/arrayfuncs.c;h=87...
Great. Thanks Tom. --DD
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2023-03-29 14:02 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 13:37 libpq: empty arrays have rank 0 in binary results? whatever the type's rank? Dominique Devienne <ddevienne@gmail.com>
2023-03-29 13:45 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-03-29 14:02 ` Dominique Devienne <ddevienne@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox