解決laravel用clickhouse查詢出現(xiàn)“Missing columns”問題

下面由laravel教程欄目給大家介紹關(guān)于在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>當(dāng)多個(gè)條件查詢時(shí),$where 數(shù)組在 sql 中會(huì)被當(dāng)成一個(gè)字段,從而導(dǎo)致 DB:: Exception: Missing columns: ‘2022-09-27 13:00:49’ ‘2022-09-27 16:00:49’ while processing query 的錯(cuò)誤。</p><p>這樣優(yōu)化:</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>多提一句:在命令行查詢時(shí),參數(shù)值使用單引號(hào),使用雙引號(hào)時(shí),參數(shù)值也會(huì)被當(dāng)成一個(gè)字段:</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?

以上就是解決

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊15 分享