I have table
create table if not exists table_name
(
id serial not null
constraint company_rules_pkey
primary key,
name varchar(255),
event_types jsonb
);
And items
INSERT INTO public.example_table (id, name, event_types) VALUES (1, 'Rule â„–1', '["1"]');
INSERT INTO public.example_table (id, name, event_types) VALUES (2, 'Rule â„–2', '["2"]');
INSERT INTO public.example_table (id, name, event_types) VALUES (3, 'Rule â„–3', '["1", "3"]');
INSERT INTO public.example_table (id, name, event_types) VALUES (4, 'Rule â„–4', '["2", "3"]');
I try to get items with like SQL query
SELECT * FROM "company_rules" WHERE "event_types" ?| array['1', '3'];
With PHP code like this
ExampleTable::find()->andWhere(['?|', 'event_types', new ArrayExpression([1, 3], 'integer')])->all();
And I expect to get a list AR but I get error
SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
Failed to prepare SQL: SELECT COUNT(*) FROM "example_table" WHERE ("event_types" ?| ARRAY[:qp0, :qp1]::integer[]) in /app/vendor/yiisoft/yii2/db/Command.php:264
| Q | A
| ---------------- | ---
| Yii version | 2.0.15.1
| PHP version | 7.0.28
| Operating system | Linux
PDO seems to understand ? as a special character and tries to replace it with params.
I doubt we can do anything about ? and PDO... Do I remember correctly that all these operands were available as functions as well?
@samdark yes, the operators' information are available in pg_operator catalog.
@asamats See https://github.com/yiisoft/yii2/issues/15873#issuecomment-372767226
Most helpful comment
references: