Обсуждение: libpq PQexecParams and arrays
Hi, I wish to call PQexecParams with array of uint32_t values. I've tried to use example from src/test/examples/testlibpq3.c, but with no effect - it's unusable for input array. Have anyone an idea, how it can be done? Thanks
on 6/7/06 2:54 AM, slynko@tronet.ru purportedly said: >>> I wish to call PQexecParams with array of uint32_t values. >>> I've tried to use example from src/test/examples/testlibpq3.c, but with >>> no effect - it's unusable for input array. >>> >>> Have anyone an idea, how it can be done? >> >> Have you tried passing all parameters, including especially the appropriate >> paramTypes and paramFormats parameters? > Of course > >> I believe that doing this should >> permit libpq to understand binary data. > No, it doesn't. > I've found, that array parsed at the server side by array_recv function. > Is there is a way to send an array of arbitrary type by libpq? To make sure that I understand, do you mean passing a paramValues as an array of uint32, or passing values to a *column* that is an array column? If it's the latter (array column), I don't think libpq supports array columns in this way. If it is just a matter of passing binary numeric values, I thought it was supported by libpq, but maybe not. The documentation is ambiguous in many places, so it is possible that libpq's binary support is only for blobs and not for other data types. I have never tried passing binary data, as I tend to find it easier in my applications to pass textual representations, so I can't say for sure. You may have to "convert" your int array into an array of char. Best, Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business"
Keary Suska <hierophant@pcisys.net> writes:
> To make sure that I understand, do you mean passing a paramValues as an
> array of uint32, or passing values to a *column* that is an array column? If
> it's the latter (array column), I don't think libpq supports array columns
> in this way.
If you're trying to pass a binary parameter value to an array column,
you have to create the correct struct representing an array datatype,
as expected by array_recv. This implies making the appropriate array
header and (for integer data) converting each value to big-endian byte
order. A plain C uint32[] array definitely hasn't got the header, and
on Intel platforms it's the wrong byte order too. There is not anything
built into libpq that will do the translation for you.
regards, tom lane
Alexey Slynko <slynko@tronet.ru> writes:
> I don't think, that it's a good idea to construct it by hand, because
> array_recv is an internal backend function,
> and format can be changed at any time
No, the on-the-wire binary formats are intended to be stable. They're
rather poorly documented :-( but they aren't something we will change
lightly.
regards, tom lane