Yii Postgress Json queries for operator with question marks ?, ?|, ?&

倖福魔咒の 提交于 2019-12-12 05:38:51

问题


How to write SQL queries to support JSON where conditions matching for operators ? , ?|, ?&.

id : 12,
name: 'Harry Pottor',
type: ['Fiction', 'Horror', 'Adventure' ]

In Yii, when I write query for JSON array check with ?& operator gives me error. This query run successfully in pgAdmin

SELECT id, name 
FROM books 
WHERE 
type ?& array['Fiction', 'Horror']

$commandSql = $connection->createCommand($sql);

But ? mark operator gets replaced with $1 i.e. going for bind value.

How to do this type of queries in Yii?


回答1:


I face same problem

SELECT * FROM company WHERE jsonb_exists_all(technology::jsonb, array['ERP']);

or

SELECT * FROM company WHERE jsonb_exists_all(technology, array['ERP']);

refer this link http://www.scriptscoop2.com/t/984beb7bce86/postgresql-json-select-query-replacement-in-php-yii2.html



来源:https://stackoverflow.com/questions/37677518/yii-postgress-json-queries-for-operator-with-question-marks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!