Search Postgresql Archives

Re: arrays returned in text format

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx> wrote:
Konstantin Izmailov <pgfizm@xxxxxxxxx> 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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux