>  기사  >  PHP 프레임워크  >  laravel이 clickhouse 쿼리를 사용할 때 "열 누락" 문제 해결

laravel이 clickhouse 쿼리를 사용할 때 "열 누락" 문제 해결

藏色散人
藏色散人앞으로
2022-10-31 16:00:313037검색

다음 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' 쿼리 처리 중 오류가 발생했습니다.

다음과 같이 최적화하세요:

   $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 쿼리를 사용할 때 "열 누락" 문제 해결의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 learnku.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제