使用 clickhouse
尤其注意:不能这么写!
$where = [];
if($cookieId) {
$where['cookie_id'] = $cookieId;
}
if($host) {
$where['host'] = $host;
}
if($uri) {
$where['uri'] = $uri;
}
$builder = DB::connection('clickhouse')
->table((new AccessLogs)->getTable())
->where($where);
if(!empty($startTime)) {
$builder->where('create_time', '>=', $startTime);
}
if(!empty($endTime)) {
$builder->where('create_time', '<=', $endTime);
}
当多个条件查询时,$where 数组在 sql 中会被当成一个字段,从而导致 DB:: Exception: Missing columns: ‘2022-09-27 13:00:49’ ‘2022-09-27 16:00:49’ while processing query 的错误。
这样优化:
$builder = DB::connection('clickhouse')
->table((new AccessLogs)->getTable());
if(!empty($cookieId)) {
$builder->where('cookie_id', $cookieId);
}
if(!empty($host)) {
$builder->where('host', $host);
}
if(!empty($uri)) {
$builder->where('uri', $uri);
}
if(!empty($startTime)) {
$builder->where('create_time', '>=', $startTime);
}
if(!empty($endTime)) {
$builder->where('create_time', '<=', $endTime);
}
才能正确查询。
多提一句:在命令行查询时,参数值使用单引号,使用双引号时,参数值也会被当成一个字段:
正确操作是:
select * from access_log where create_time >= ‘2022-09-27 13:00:49’ and create_time <= ‘2022-09-27 16:00:49’ order by create_time desc limit 10;
以上就是解决laravel用clickhouse查询出现“Missing columns”问题的详细内容
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)