I've a table created like:
CREATE TABLE tbl_test
(
id bigserial PRIMARY KEY,
interest int ARRAY[2]
);
I got PGresult* res
using PQexec(conn, "SELECT * FROM tbl_test");
Now, how can I get int[]
from PQgetvalue(res, 0, 1)
.
I don't want to depend on structs defined in array.h
as they might change.
I could not find any API in Postgresql docs which can do things.
Please advise.
Regards,
Mayank
PQgetvalue() returns the string representation of the field value unless you specify a binary cursor. In either case (string or binary cursor) you'll need to supply the code to manipulate the result into the form you want.
You might find some ideas in the PostgreSQL source code.
And there's some code in contrib/intarray.
At http://doxygen.postgresql.org/, click "Files", then search for "array".
At the string level, which is what PQgetvalue() returns, it's probably easy to Google up some code that extracts integers from an comma-delimited string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With