heroku Pgsql错误:您可能需要添加显式类型强制转换

a11xaf1n  于 9个月前  发布在  其他
关注(0)|答案(3)|浏览(103)

我的网站只是工作正常,直到我部署到heroku和问题是heroku使用pgsql和我使用mysql和laravel框架。
我的疑问是

$patient = Patient::where('patient_address', 'ILIKE' ,'%' . $request->input)->where('patient_sex', 'ILIKE' ,'%' . $request->gender)->whereHas('users', function($q) use($vaccine_id){
        $q->where('vaccine_id','ILIKE','%' . $vaccine_id);
    })->get();

这是我把它部署到Heroku时得到的结果
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: integer ~~* unknown LINE 1: ...ient_id" = "patients"."PatientID" and "vaccine_id" ILIKE $3)
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. (SQL: select * from "patients" where "patient_address" ILIKE %San Francisco and "patient_sex" ILIKE % and exists (select * from "vaccines" inner join "immunizations" on "vaccines"."VaccineID" = "immunizations"."vaccine_id" where "immunizations"."patient_id" = "patients"."PatientID" and "vaccine_id" ILIKE %))
我试过使用像CAST(vaccine_id AS VARCHAR)这样的类型转换,我没有得到错误,但它没有返回任何结果。

9avjhtql

9avjhtql1#

问题就在这里:

$q->where('vaccine_id','ILIKE','%' . $vaccine_id)

看起来vaccine_id是整型的,你不能使用操作符ILIKE来整型。试试“=”
如果你想使用LIKE,ILIKE或其他文本操作符,你必须将数据转换为文本。在SQL中,它看起来像:

WHERE "vaccine_id"::text ILIKE val

相反

WHERE "vaccine_id" ILIKE val
bhmjp9jg

bhmjp9jg2#

你可以这样做:

$q->where('cast(vaccine_id AS VARCHAR)','LIKE','%' . $vaccine_id)

$q->where('cast(vaccine_id AS TEXT)','LIKE','%' . $vaccine_id)
luaexgnf

luaexgnf3#

显式强制转换是必须使用CAST AS关键字或强制转换运算符(::)

相关问题