使用node-pg我尝试查找JSON对象中是否存在字符串。
示例(部分)行:
{ viq_id: '801583',
title: 'Blank, security key, lock system, and production method',
applicants: [ [Object], [Object] ],
cpc: [ [Object], [Object] ],
abstract: { value: [Object], language: 'en' } }
abstract的类型为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?
答案 0 :(得分:3)
将var query = 'SELECT viq_id, title, applicants, cpc, abstract ->> "value"'
更改为var query = "SELECT viq_id, title, applicants, cpc, abstract ->> 'value'"
,因为用于db对象(表,列等)的双引号名称...
看看Postgres JSON syntax