Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

352
Visualizações
Different result beween eloquent query and the same associated SQL query (got with toSql() method ) with Laravel

I have this query in Laravel Eloquent:

$measures = Measure::groupBy('time')
        ->selectRaw('time, sum("delta") as sum_delta, sum("redistributed") as sum_redistr') 
        ->where('operation_id', 'ACC0000001') 
        ->where('time', '>', '2020-05-09 00:00') 
        ->where('time', '<', '2020-05-10 00:00') 
        ->where('source', 'source1') 
        ->where('conso_prod', 'Conso')
        ->get()

When I debug using toSql() function, and then I paste it into pgAdmin, I get the correct result.

select time, sum("delta") as sum_delta, sum("redistributed") as sum_redistr from "measures" 
where "operation_id" = 'ACC0000001'
and "time" > '2020-05-09' and "time" < '2020-05-10' and "source" = 'source1' and "conso_prod" = 'Conso' group by "time"

And I have a result each 30m which is correct.

But when I use eloquent, I have the same amount of rows, but all the time fields are the same:

"2020-05-09 00:00"

instead of incrementing.

I don't understand why ? I use PostgreSQL with TimescaleDB extension.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

In my model, I had my time casted to date instead of datetime

protected $casts = [
    'time' => 'date'
];

I changed it to :

protected $casts = [
    'time' => 'datetime'
];

And it worked.

I let it there if someones fails like me ! Thanks for your help anyway

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda