Skip to content

PostgreSQL: Invalid parameter number if use jsonb #16046

@asamats

Description

@asamats

What steps will reproduce the problem?

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();

What is the expected result?

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

Additional info

Q A
Yii version 2.0.15.1
PHP version 7.0.28
Operating system Linux

PostgreSQL.Doc 9.15. JSON Functions and Operators

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions