PostgreSQL & ARRAY: ERROR: syntax error at or near "ANY"

Trabla:  PostgreSQL & ARRAY: ERROR:  syntax error at or near "ANY"

Example:

CREATE TABLE tbl_cars ( id BIGSERIAL PRIMARY KEY, name varchar(200), price double precision  );
INSERT INTO tbl_cars(name,price) VALUES('bmw m5', 50000);
INSERT INTO tbl_cars(name,price) VALUES('bmw m6', 60000);
INSERT INTO tbl_cars(name,price) VALUES('toyota land cruiser', 80000);
INSERT INTO tbl_cars(name,price) VALUES('ferrari f430', 250000);
INSERT INTO tbl_cars(name,price) VALUES('mercedes-benz ml 450', 70000);

SELECT name, price
FROM
    tbl_cars AS cars
WHERE
    cars.name ANY (  ARRAY['bmw m5','mercedes-benz ml 450'] );


Error:

ERROR:  syntax error at or near "ANY"
LINE 13:  cars.name ANY (  ARRAY['bmw m5','mercedes-benz ml 450'] );
                    ^
********** Error **********

ERROR: syntax error at or near "ANY"
SQL state: 42601
Character: 514


Solving:

use  = ANY

SELECT name, price
FROM
    tbl_cars AS cars
WHERE
    cars.name = ANY (  ARRAY['bmw m5','mercedes-benz ml 450'] );


Result:
 name | price
"bmw m5";50000
"mercedes-benz ml 450";70000

 

 

No comments:

Post a Comment