libpq: empty arrays have rank 0 in binary results? whatever the type's rank? - Mailing list pgsql-general

From Dominique Devienne
Subject libpq: empty arrays have rank 0 in binary results? whatever the type's rank?
Date
Msg-id CAFCRh-82ACBOdFA3BxevZQn4AZuUTi6Z5-q1T99OE=tM5hA9cw@mail.gmail.com
Whole thread Raw
Responses Re: libpq: empty arrays have rank 0 in binary results? whatever the type's rank?
List 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);

pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Move from MySQL to PostgreSQL
Next
From: Tom Lane
Date:
Subject: Re: libpq: empty arrays have rank 0 in binary results? whatever the type's rank?