2015-05-07 153 views
3

使用node-pg我試圖查找一個JSON對象內的字符串的存在。節點Postgres查詢json

實施例(的部分)排:

{ viq_id: '801583', 
    title: 'Blank, security key, lock system, and production method', 
    applicants: [ [Object], [Object] ], 
    cpc: [ [Object], [Object] ], 
    abstract: { value: [Object], language: 'en' } } 

抽象的類型是JSONB的。 當查詢此

var query = 'SELECT viq_id, title, applicants, cpc, abstract ->> "value"' + 
    ' FROM epo_patents' + 
    ' WHERE title ILIKE $1'; 

或本

var query = 'SELECT viq_id, title, applicants, cpc, abstract' + 
     ' FROM epo_patents' + 
     ' WHERE title ILIKE $1 OR abstract ->> "value" = $1'; 

或本

var query = 'SELECT viq_id, title, applicants, cpc, abstract' + 
     ' FROM epo_patents' + 
     ' WHERE abstract.value = $1'; 

答案是 「errorMissingColumn」,或者在後一種情況下errorMissingRTE

如何我在節點pg中正確查詢JSON?

回答

2

變化var query = 'SELECT viq_id, title, applicants, cpc, abstract ->> "value"'var query = "SELECT viq_id, title, applicants, cpc, abstract ->> 'value'",因爲用於數據庫對象(表,列等)的名稱雙引號... 看看Postgres JSON syntax