nicolaslopezj / searchable

A php trait to search laravel models
MIT License
2.01k stars 291 forks source link

Works fine on MySql but not on pgSQL #95

Closed MangTomas23 closed 8 years ago

MangTomas23 commented 8 years ago

It works really fine on mySQL but when I run it on Heroku that is using pgSQL it returns a QueryException

SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "."
LINE 1: ...om (select "users".*, avg((case when LOWER(`users`.`firstnam...
^ (SQL: select * from (select "users".*, avg((case when LOWER(`users`.`firstname`) ILIKE jean then 150 else 0 end) + (case when LOWER(`users`.`firstname`) ILIKE jean% then 50 else 0 end) + (case when LOWER(`users`.`firstname`) ILIKE %jean% then 10 else 0 end) + (case when LOWER(`users`.`middlename`) ILIKE jean then 150 else 0 end) + (case when LOWER(`users`.`middlename`) ILIKE jean% then 50 else 0 end) + (case when LOWER(`users`.`middlename`) ILIKE %jean% then 10 else 0 end) + (case when LOWER(`users`.`lastname`) ILIKE jean then 150 else 0 end) + (case when LOWER(`users`.`lastname`) ILIKE jean% then 50 else 0 end) + (case when LOWER(`users`.`lastname`)....
lperry65 commented 6 years ago

Having similar issue:

SQLSTATE[42883]: Undefined function: 7 ERROR: function lower(numeric) does not exist LINE 1: ...iption) ILIKE $6 then 10 else 0 end) + (case when LOWER(prod... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. (SQL: select count() as aggregate from (select "products"., max((case when LOWER(products.product_code) ILIKE chicken then 75 else 0 end) + (case when LOWER(products.product_code) ILIKE chicken% then 25 else 0 end) + (case when LOWER(products.product_code) ILIKE %chicken% then 5 else 0 end) + (case when LOWER(products.description) ILIKE chicken then 150 else 0 end) + (case when LOWER(products.description) ILIKE chicken% then 50 else 0 end) + (case when LOWER(products.description) ILIKE %chicken% then 10 else 0 end) + (case when LOWER(products.price) ILIKE chicken then 225 else 0 end) + (case when LOWER(products.price) ILIKE chicken% then 75 else 0 end) + (case when LOWER(products.price) ILIKE %chicken% then 15 else 0 end)) as relevance from "products" group by "products"."product_code" having (case when LOWER(products.product_code) ILIKE chicken then 75 else 0 end) + (case when LOWER(products.product_code) ILIKE chicken% then 25 else 0 end) + (case when LOWER(products.product_code) ILIKE %chicken% then 5 else 0 end) + (case when LOWER(products.description) ILIKE chicken then 150 else 0 end) + (case when LOWER(products.description) ILIKE chicken% then 50 else 0 end) + (case when LOWER(products.description) ILIKE %chicken% then 10 else 0 end) + (case when LOWER(products.price) ILIKE chicken then 225 else 0 end) + (case when LOWER(products.price) ILIKE chicken% then 75 else 0 end) + (case when LOWER(products.price) ILIKE %chicken% then 15 else 0 end) >= 7.50 order by "relevance" desc) as products)

lperry65 commented 6 years ago

SQLSTATE[42803]: Grouping error: 7 ERROR: column "products.description" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: select count() as aggregate from (select "products"., max(... ^ (SQL: select count() as aggregate from (select "products"., max((case when LOWER(products.product_code) ILIKE chicken then 75 else 0 end) + (case when LOWER(products.product_code) ILIKE chicken% then 25 else 0 end) + (case when LOWER(products.product_code) ILIKE %chicken% then 5 else 0 end) + (case when LOWER(products.description) ILIKE chicken then 150 else 0 end) + (case when LOWER(products.description) ILIKE chicken% then 50 else 0 end) + (case when LOWER(products.description) ILIKE %chicken% then 10 else 0 end) + (case when LOWER(products.price) ILIKE chicken then 225 else 0 end) + (case when LOWER(products.price) ILIKE chicken% then 75 else 0 end) + (case when LOWER(products.price) ILIKE %chicken% then 15 else 0 end)) as relevance from "products" group by "products"."product_code" having (case when LOWER(products.product_code) ILIKE chicken then 75 else 0 end) + (case when LOWER(products.product_code) ILIKE chicken% then 25 else 0 end) + (case when LOWER(products.product_code) ILIKE %chicken% then 5 else 0 end) + (case when LOWER(products.description) ILIKE chicken then 150 else 0 end) + (case when LOWER(products.description) ILIKE chicken% then 50 else 0 end) + (case when LOWER(products.description) ILIKE %chicken% then 10 else 0 end) + (case when LOWER(products.price) ILIKE chicken then 225 else 0 end) + (case when LOWER(products.price) ILIKE chicken% then 75 else 0 end) + (case when LOWER(products.price) ILIKE %chicken% then 15 else 0 end) >= 7.50 order by "relevance" desc) as products where "product_code" in (152, 1442, 1818, 265597))

SezerFidanci commented 4 years ago

Hey, add constraint primary key id column on products table