postgresql - Pgsql 错误 : You might need to add explicit type casts

标签 postgresql heroku

在我将其部署到 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/

相关文章:

database - Visual Studio 2008 中的 PostgreSQL 数据连接/服务器资源管理器

python - 使用 Pytest 在函数中模拟引发异常

node.js - Nodemailer "Error: Missing credentials for "PLAIN“Gmail API 凭据之后

css - Rails 5 - 用户指定的 CSS 在具有自定义域的 Heroku 上不起作用

sql - 识别客户最近一天访问的第一页

java - 如何在事务打开后立即查询 SQL?

django - 带有 Django 和 postgres 的 Heroku 应用程序意外崩溃

heroku - 为 Rails 4 应用程序加速 Heroku 部署

postgresql - 使用索引转储 Postgres 9.3 数据

ruby-on-rails - 设计确认链接将用户重定向到 heroku 域而不是自定义域