Re: array_agg and libpq(xx) - Mailing list pgsql-general

From John R Pierce
Subject Re: array_agg and libpq(xx)
Date
Msg-id 49C2B472.30300@hogranch.com
Whole thread Raw
In response to array_agg and libpq(xx)  (Grzegorz Jaśkiewicz <gryzman@gmail.com>)
Responses Re: array_agg and libpq(xx)  (Grzegorz Jaśkiewicz <gryzman@gmail.com>)
List pgsql-general
Grzegorz Jaśkiewicz wrote:
> Hi,
>
> Anyone here passed array to C/c++ code via libpq(xx) ??
>

Do you mean, fetching the output of a query like

    SELECT ARRAY['123','456','abc','def'];

?

> I need to pass on an array of strings, some of them might contain coma symbol.
> I am wondering, if there's anything already in libpq(xx) that would
> chop value into an array of char* , or will it just return a string
> and it is up to user to chop it.
>

    pgResult = PQexec(pgConn, "select array['123','456','abc','def'];");
    pgarray = PQgetvalue(pgResult,0,0);

will return a pointer to the ARRAY in postgres format as defined by the
typsend/recieve internal functions for the ARRAY type.   you would need
to walk this and copy the strings comprising the array to your own
managed storage (malloc, or whatever) prior to calling
PQclear(pgResult).   I'm trying to find the docs on what the typsend
format for ARRAY looks like and failing.




pgsql-general by date:

Previous
From: ray
Date:
Subject: Re: Installation Error, Server Won't Start
Next
From: "Dann Corbit"
Date:
Subject: Re: Is there a meaningful benchmark?