搜尋
首頁php框架Laravel解決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')
        ->table((new AccessLogs)->getTable())
        ->where($where);
    if(!empty($startTime)) {
        $builder->where('create_time', '>=', $startTime);
    }
    if(!empty($endTime)) {
        $builder->where(&#39;create_time&#39;, &#39;<=&#39;, $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(&#39;clickhouse&#39;)
        ->table((new AccessLogs)->getTable());
    if(!empty($cookieId)) {
        $builder->where(&#39;cookie_id&#39;, $cookieId);
    }        
    if(!empty($host)) {
        $builder->where(&#39;host&#39;, $host);
    }        
    if(!empty($uri)) {
        $builder->where(&#39;uri&#39;, $uri);
    }
    if(!empty($startTime)) {
        $builder->where(&#39;create_time&#39;, &#39;>=&#39;, $startTime);
    }
    if(!empty($endTime)) {
        $builder->where(&#39;create_time&#39;, &#39;<=&#39;, $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」問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:learnku。如有侵權,請聯絡admin@php.cn刪除
使用Laravel Blade在全棧項目中進行前端模板使用Laravel Blade在全棧項目中進行前端模板May 01, 2025 am 12:24 AM

laravelbladeenhancesfrontendtemplatinginflatinginflationll-stackprojectsbyferingCleanSyntaxandaxandpoperfelfulfeatures.1)itallowsforeasyvariableasyvariabledisplayandControlstructures.2)bladesuportsuportsuportscreatingingingingingingingingingingangingandredreingscomponents components components components,aidinginmanagingcomplexuis.3)

使用Laravel:實用教程構建全堆棧應用程序使用Laravel:實用教程構建全堆棧應用程序May 01, 2025 am 12:23 AM

laravelisidealforll-stackapplicationsduetoitselegantsyntax,complastissionecosystem和perperatedfulfeatures.1)useeloquentormforintuivelbackenddatamanipulation,butavoidn 1queryissues.2)

您使用哪種工具來保持遠程角色保持連接?您使用哪種工具來保持遠程角色保持連接?May 01, 2025 am 12:21 AM

forremotework,iusezoomforvideOcalls,Slackformessing,trelloforprojectmanagement,and giThubForCodeCollaboration.1)Zoomisreliable forlailible forlargemeetingsbuthastimelimitsonthefreeversion.2)

遠程訪問和屏幕共享:橋接技術支持的距離遠程訪問和屏幕共享:橋接技術支持的距離May 01, 2025 am 12:07 AM

remoteaccessandscreensharingworkbyestablishingasecure,real-timeconnectionbetweencomputerssusterprotococolslikerdp,vnc,orproprietarysoltions.bestpracticessinclude:1)構建thrustthroustthroustthroustthroudthrouftthroughclearcommunication,2)2)SeneruringSecuringSecurityWithStrongentStrongentStrongentStrongentscorneptermeptimptermeptimplemptymentponempts和Dat

值得升級到最新的Laravel版本嗎?值得升級到最新的Laravel版本嗎?May 01, 2025 am 12:02 AM

絕對值得考慮升級到最新的Laravel版本。 1)新功能和改進,如匿名遷移,提升了開發效率和代碼質量。 2)安全性提升,修復了已知漏洞。 3)社區支持增強,提供了更多資源。 4)需評估兼容性,確保平穩升級。

Laravel 日誌與錯誤監控:Sentry 和 Bugsnag 集成Laravel 日誌與錯誤監控:Sentry 和 Bugsnag 集成Apr 30, 2025 pm 02:39 PM

在Laravel中集成Sentry和Bugsnag可以提高應用的穩定性和性能。 1.在composer.json中添加SentrySDK。 2.在config/app.php中添加Sentry服務提供者。 3.在.env文件中配置SentryDSN。 4.在App\Exceptions\Handler.php中添加Sentry錯誤報告。 5.使用Sentry捕獲並報告異常,並添加額外上下文信息。 6.在App\Exceptions\Handler.php中添加Bugsnag錯誤報告。 7.使用Bugsnag監

為什麼 Laravel 依然是 PHP 開發者的首選框架?為什麼 Laravel 依然是 PHP 開發者的首選框架?Apr 30, 2025 pm 02:36 PM

Laravel依然是PHP开发者的首选框架,因为它在开发体验、社区支持和生态系统上表现卓越。1)其优雅的语法和丰富的功能集,如EloquentORM和Blade模板引擎,提升了开发效率和代码可读性。2)庞大的社区提供了丰富的资源和支持。3)尽管学习曲线较陡且可能导致项目复杂性增加,但通过合理配置和优化,Laravel能显著提升应用性能。

Laravel 實時聊天應用:WebSocket 與 Pusher 結合Laravel 實時聊天應用:WebSocket 與 Pusher 結合Apr 30, 2025 pm 02:33 PM

在Laravel中構建實時聊天應用需要使用WebSocket和Pusher。具體步驟包括:1)在.env文件中配置Pusher信息;2)設置broadcasting.php文件中的廣播驅動為Pusher;3)使用LaravelEcho訂閱Pusher頻道並監聽事件;4)通過PusherAPI發送消息;5)實現私有頻道和用戶認證;6)進行性能優化和調試。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境