libpq: empty arrays have rank 0 in binary results? whatever the type's rank?

From: Dominique Devienne <ddevienne(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: libpq: empty arrays have rank 0 in binary results? whatever the type's rank?
Date: 2023-03-29 13:37:10
Message-ID: CAFCRh-82ACBOdFA3BxevZQn4AZuUTi6Z5-q1T99OE=tM5hA9cw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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);

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-03-29 13:45:23 Re: libpq: empty arrays have rank 0 in binary results? whatever the type's rank?
Previous Message Thomas Kellerer 2023-03-29 13:34:29 Re: Move from MySQL to PostgreSQL