Re: libpq PQexecParams and arrays

Lists: pgsql-interfaces
From: Keary Suska <hierophant(at)pcisys(dot)net>
To: Alexey Slynko <slynko(at)tronet(dot)ru>
Cc: Postgres-Interfaces <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: libpq PQexecParams and arrays
Date: 2006-06-07 16:05:32
Message-ID: C0AC556C.2B270%hierophant@pcisys.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

on 6/7/06 2:54 AM, slynko(at)tronet(dot)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"


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Keary Suska <hierophant(at)pcisys(dot)net>
Cc: Alexey Slynko <slynko(at)tronet(dot)ru>, Postgres-Interfaces <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: libpq PQexecParams and arrays
Date: 2006-06-07 16:39:04
Message-ID: 927.1149698344@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Keary Suska <hierophant(at)pcisys(dot)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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexey Slynko <slynko(at)tronet(dot)ru>
Cc: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: libpq PQexecParams and arrays
Date: 2006-06-07 17:20:02
Message-ID: 3720.1149700802@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Alexey Slynko <slynko(at)tronet(dot)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