Somnath Muluk Somnath Muluk - 1 year ago 86
PHP Question

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

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
type ?& array['Fiction', 'Horror']

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

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

How to do this type of queries in Yii?

Answer Source

I face same problem

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


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

refer this link

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download