解决laravel用clickhouse查询出现“Missing columns”问题

下面由laravel教程栏目给大家介绍关于在laravel中使用clickhouse查询引起的“db::exception: missing columns”问题,希望对大家有所帮助!

使用 clickhouse 尤其注意:不能这么写!

   $where = [];     if($cookieId) {         $where['cookie_id'] = $cookieId;     }             if($host) {         $where['host'] = $host;     }             if($uri) {         $where['uri'] = $uri;     }     $builder = DB::connection('clickhouse')         -&gt;table((new AccessLogs)-&gt;getTable())         -&gt;where($where);     if(!empty($startTime)) {         $builder-&gt;where('create_time', '&gt;=', $startTime);     }     if(!empty($endTime)) {         $builder-&gt;where('create_time', '<p>当多个条件查询时,$where 数组在 sql 中会被当成一个字段,从而导致 DB:: Exception: Missing columns: ‘2022-09-27 13:00:49’ ‘2022-09-27 16:00:49’ while processing query 的错误。</p><p>这样优化:</p><pre class="brush:php;toolbar:false">   $builder = DB::connection('clickhouse')         -&gt;table((new AccessLogs)-&gt;getTable());     if(!empty($cookieId)) {         $builder-&gt;where('cookie_id', $cookieId);     }             if(!empty($host)) {         $builder-&gt;where('host', $host);     }             if(!empty($uri)) {         $builder-&gt;where('uri', $uri);     }     if(!empty($startTime)) {         $builder-&gt;where('create_time', '&gt;=', $startTime);     }     if(!empty($endTime)) {         $builder-&gt;where('create_time', '<p>才能正确查询。</p><p>多提一句:在命令行查询时,参数值使用单引号,使用双引号时,参数值也会被当成一个字段:</p><p><strong>正确操作是:</strong></p><pre class="brush:php;toolbar:false">select * from access_log where create_time &gt;= ‘2022-09-27 13:00:49’ and create_time 

以上就是解决

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享