0

I have a postgreSQL database that stores all changes to table in json format, new_val and old_val
It looks like this

new_val

  {"id":6,"id_item_type":7,"id_contact_as_producer":2,"id_contact_as_owner": 2,"comment":"3213","id_item_status":1,"imageurl":null,"id_station":2,"audit_id":null}";"  

old_val

{"id":6,"id_item_type":7,"id_contact_as_producer":2,"id_contact_as_owner":2,"comment":"3213","id_item_status":1,"imageurl":null,"id_station":null,"audit_id":null}"

I can query this easily in pgadmin with the sql command

SELECT * FROM audit.history WHERE new_val ->> 'id_item_type' = '7'  

But when I try to query it from nodejs with PG it just hangs. I think it is because PG gets it input as a string

var query = client.query('SELECT * FROM audit.history WHERE new_val ->> 'id_item_type' = '7'', 
        function (err, result) {
            done();
    });

So my question is basically, how can I use query the db from PG in Node to give me the same result?

Hundurinn Nero
  • 83
  • 1
  • 2
  • 14
  • Try instead: `client.query('SELECT * FROM audit.history WHERE new_val ->> id_item_type = 7',` (some quotes removed, not needed and wrong syntax) – michelem Dec 08 '15 at 11:11
  • It did not work, it seems that only id_item_type and 7 can be string and the rest not but then PG won't accept it. – Hundurinn Nero Dec 08 '15 at 11:38

0 Answers0