Tony Reina wrote:
> I'm using the C library (lipq) to grab data from a field that contains
> a float array (float4). I'd like to fill an array in my C program
> with these values. Unfortunately, Postgres returns the array as a
> large string instead of individual values.
> Now I could perform "select array_var, array_var, array_var,
> ..., array_var" and have each array value come back as a different
> field, but this seems fairly messy. I suppose I could also go through
> and parse the characters in the string returned.
> Has anyone else used any other strategies to fill their C array with
> an array returned from the libpq? Perhaps there are some SQL functions
> for arrays that might exist?
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.
In response to
pgsql-sql by date
|Next:||From: Andreas Pflug||Date: 2003-03-26 19:08:41|
|Subject: Re: UPDATE FROM portability|
|Previous:||From: Stephan Szabo||Date: 2003-03-26 18:44:33|
|Subject: Re: order by|