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)
.
array.h
as they might change.
I could not find any API in Postgresql docs which can do th开发者_如何学Goings.
Please advise.Regards,
MayankPQgetvalue() 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.
- src/backend/utils/adt/arrayfuncs.c
- src/include/utils/array.h.
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.
精彩评论