0

PostgreSQL-9.4, PHP-7.

I have a table 'items' with the following structure:

user_id integer references users(user_id),
item_id integer,
is_removed numeric (1) default 0,
unix integer default EXTRACT(epoch FROM CURRENT_TIMESTAMP),
title varchar (30),
text text default null

\d+ items in psql shows that 'user_id' is really integer, 'text' is really text and so on.

Then I insert the respective data, and select it like:

SELECT * FROM items WHERE user_id = $1 AND item_id = ANY($2::int[]) LIMIT 1;

And the following code outputs 'string string string string string string':

while ($row = pg_fetch_assoc($data)) {
    foreach ($row AS $val) {
        echo gettype($val) . ' ';
    }
}

Is it alright? And is it possible to make PG to return integers?

aspermag
  • 157
  • 1
  • 7
  • I'd suggest adding the PHP flag here, since this behavior has more to do with the PHP postgres client than the DBMS itself – Nick Bailey Jun 03 '16 at 12:35
  • 1
    If I understand correctly, all `pg_fetch_*` functions returns the string representation of values (see the `Return Values` section of their [docs](http://php.net/manual/en/function.pg-fetch-assoc.php)) like in the linked duplicate. If I remember well, `PDO` used the correct types for results (the last time I used it). – pozs Jun 03 '16 at 13:16

0 Answers0