From: G. Anthony Reina <gar8+@pitt.edu>
To: Joe Conway <mail@joeconway.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: How can I pass an array from PostgreSQL to C (libpq)?
Date: Wed, 26 Mar 2003 17:47:11 -0500
Message-ID: <519653832.1048700831@dell1.neurobio.pitt.edu> (raw)
In-Reply-To: <3E81FA6A.8090201@joeconway.com>
References: <3E81FA6A.8090201@joeconway.com>
Yes, in the past I had used binary cursor and things seemed to work fine.
However, recently when I ran the binary cursor stuff, the array ends up
getting shifted to the right one index. So what should be placed in
array_var[n] was getting placed in array var[n+1]. Plus, I was always a
little concerned with the binary cursor when going across platforms (e.g.
endianess, alignment).
I ended up just writing a little script that parses the string for the
comma separators. That works fine, but wanted to see if others had more
elegant solutions. I'll take a look at the /utils directory you mentioned.
Perhaps there are functions that I'm not aware of (e.g. I didn't know there
was a built in function called array_dims that gives the array dimensions).
-Tony
--On Wednesday, March 26, 2003 11:07 AM -0800 Joe Conway
<mail@joeconway.com> wrote:r
>
> PQgetvalue is always going to give you the string representation of the
> field value *unless* you specify a binary cursor. In that case you'll get
> all requested fields in binary form, and it's your responsibility to deal
> with making sense of what you get. There are some backend macros and
> functions that can help you get at array values. Take a look at
> src/utils/adt/arrayfuncs.c and src/include/utils/array.h. You might want
> to read through contrib/array and/or contrib/intarray for examples.
>
> You could also consider writing your array manipulation code in a user
> defined C function and just return the end result to the libpq program.
> It's hard to know if this is an option without more detail on what you're
> trying to do.
>
> Joe
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gar8+@pitt.edu, mail@joeconway.com
Subject: Re: How can I pass an array from PostgreSQL to C (libpq)?
In-Reply-To: <519653832.1048700831@dell1.neurobio.pitt.edu>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox