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

问题描述 投票:14回答:1

我的网站工作正常,直到我将它部署到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)这样的强制转换,我没有得到错误,但它没有返回任何结果。

postgresql heroku
1个回答
16
投票

问题出在这里:

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

看起来疫苗id是整数,你不能使用运算符I LIKE来整数。试试'='

如果要使用LIKE,ILIKE或其他文本运算符,则必须将数据转换为文本。在SQL中它必须看起来像:

WHERE "vaccine_id"::text ILIKE val

代替

WHERE "vaccine_id" ILIKE val
© www.soinside.com 2019 - 2024. All rights reserved.