Re: arrays returned in text format

Поиск
Список
Период
Сортировка
От Konstantin Izmailov
Тема Re: arrays returned in text format
Дата
Msg-id CAAw-MsdVVaVB8LFUvbpjgfsPyWn8A5a3PdHr=EXs-bSkAZdrHA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: arrays returned in text format  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: arrays returned in text format  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Oops, I forgot to mention that we slightly modified libpq to request resulting fields formats (since Postgres protocol v3 supports this). See our additions in Bold:

PQexec(PGconn *conn, const char *query, int resultFormatCount, const int* resultFormats)
{
    if (!PQexecStart(conn))
        return NULL;
    if (!PQsendQuery(conn, query, resultFormatCount, resultFormats))
        return NULL;
    return PQexecFinish(conn, 0);
}

where PQsendQuery passes requested format in the Bind message:

        /* construct the Bind message */
        if (pqPutMsgStart('B', false, conn) < 0 ||
            pqPuts("", conn) < 0 ||
            pqPuts(""/* use unnamed statement */, conn) < 0)
            goto sendFailed;

        /* no parameters formats */
        if (pqPutInt(0, 2, conn) < 0)
            goto sendFailed;

        if (pqPutInt(0, 2, conn) < 0)
            goto sendFailed;

        if (pqPutInt(resultFormatCount, 2, conn) < 0)
            goto sendFailed;

        for (i = 0; i < resultFormatCount; i++)
        {
            if (pqPutInt(resultFormats[i], 2, conn) < 0)
                goto sendFailed;
        }


The above is being used for about 10 years in our variant of libpq. It works for everything except for the case with ARRAY.

Thank you for the quick reply!


On Fri, Mar 4, 2016 at 10:03 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Konstantin Izmailov <pgfizm@gmail.com> writes:
> I'm using libpq to read array values, and I noticed that sometimes the
> values are returned in Binary and sometimes - in Text format.

> 1. Returned in Binary format:
>    int formats[1] = { 1 }; // request binary format
>    res = PQexec(conn, "SELECT rgField FROM aTable", 1, formats);
>    assert(PQfformat(res, 0) == 1);  // this is OK

> 2. Returned in Text format:
>    res = PQexec(conn, "SELECT ARRAY[1,2,3]", 1, formats);
>    assert(PQfformat(res, 0) == 1);  // this fails???

Um, that is not the call signature of PQexec(), nor of any of its
variants.

                        regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: arrays returned in text format
Следующее
От: Tom Lane
Дата:
Сообщение: Re: arrays returned in text format