Re: arrays returned in text format

From: Konstantin Izmailov <pgfizm(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: arrays returned in text format
Date: 2016-03-05 05:28:17
Message-ID: CAAw-MsdVVaVB8LFUvbpjgfsPyWn8A5a3PdHr=EXs-bSkAZdrHA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Konstantin Izmailov <pgfizm(at)gmail(dot)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
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2016-03-05 05:32:07 Re: arrays returned in text format
Previous Message Tom Lane 2016-03-05 05:03:27 Re: arrays returned in text format