在我将其部署到 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]:未定义函数:7 错误:运算符不存在:整数 ~~* 未知
第 1 行:...ient_id"= "patients"."PatientID"和 "vaccine_id"ILIKE $3)
提示:没有运算符匹配给定的名称和参数类型。您可能需要添加显式类型转换。 (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"其中 "immunizations"."patient_id"= "patients"."PatientID"和 "vaccine_id"ILIKE %)
我尝试使用像 CAST(vaccine_id AS VARCHAR) 这样的强制转换,但我没有收到错误,但它没有返回任何结果。
最佳答案
问题出在这里:
$q->where('vaccine_id','ILIKE','%' . $vaccine_id)
看起来 vaccine_id 是整数,不能使用运算符 ILIKE 来整数。尝试只使用“=”
如果您想使用 LIKE、ILIKE 或其他文本运算符,您必须将数据转换为文本。在 SQL 中,它必须看起来像:
WHERE "vaccine_id"::text ILIKE val
代替
WHERE "vaccine_id" ILIKE val
关于postgresql - Pgsql 错误 : You might need to add explicit type casts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42149496/