问题描述
我的网站工作正常,直到我将其部署到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){
$ ('vaccine_id','ILIKE','%'。$ vaccine_id);
}) - > get();
这就是我在将它部署到heroku时获得的结果
SQLSTATE [42883]:未定义函数:7错误:运算符不存在:integer ~~ *未知
LINE 1:... ient_id=患者。 PatientID和vaccine_idILIKE $ 3)
提示:没有操作符匹配给定的名称和参数类型您可能需要添加明确的类型转换(SQL:select * frompatients,其中patient_addressILIKE%旧金山和patient_sexILIKE%和存在(选择* fromvaccines内部加入免疫接种 VaccineID=immunizations。vaccine_id,其中immunizations,patient_id=患者,PatientID和vaccine_idILIKE%))
我曾尝试使用CAST(vaccine_id AS VARCHAR)类型,但我没有收到错误信息,但它没有返回任何结果。
$ q->其中('vaccine_id ','ILIKE','%'。$ vaccine_id)
看起来像vsaccine_id是整数,而你不能使用运算符ILIKE来整数。尝试'='
如果您想使用LIKE,ILIKE或其他文本运算符,您必须投射数据文本。在SQL中,看起来像
WHEREvaccine_id:: text ILIKE val
改为
WHEREvaccine_idILIKE val
My website is just working fine til i deployed it to heroku and the problem is heroku uses pgsql and I'm using mysql and laravel framework.
my query is
$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();
here's what I'm getting when I deploy it to heroku
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: integer ~~* unknownLINE 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 %))
I have tried using cast like CAST(vaccine_id AS VARCHAR) and I' not getting the error but it doesnt return any result.
The problem is here:
$q->where('vaccine_id','ILIKE','%' . $vaccine_id)
looks like vsaccine_id is integer, and you can not use operator ILIKE to integer. Try just '='
If you want to use LIKE, ILIKE or other text operator you must cast your data te text. In SQL musty looks like
WHERE "vaccine_id"::text ILIKE val
instead
WHERE "vaccine_id" ILIKE val
这篇关于Pgsql错误:您可能需要添加显式类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!