开发者

Postgresql PQgetvalue: array return

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 th开发者_如何学Goings.

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.

  • 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜