我正在尝试基于字段time`‘进行查询,以获得最后一周的数据:
Measure::where('time', '>', "NOW() - INTERVAL '12 hours'")->get();
               但我不能让它起作用。
I get this message: 
SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid input syntax for type timestamp: "NOW() - INTERVAL '12 hours'" (SQL: select * from "measures" where "time" > NOW() - INTERVAL '12 hours')
               
    
问题是,我从 官方文件 of timescaleDB获得了这个条件,应该是postgres兼容的:
从时间>现在()-间隔'12小时‘的条件中选择计数(*);
为什么会发生这种事,我该怎么办?
发布于 2020-07-23 15:28:01
我认为您需要使用whereRaw,因为表达式中有函数调用。
Measure::whereRaw("time > NOW() - INTERVAL '12 hours'")->get();
                   发布于 2020-07-23 15:29:38
                   
                    
                     
                      
                       
                        
                         
                          
                           
                            
                             
                              
                               
                                
                                 
                                  
                                   
                                    尝试没有引号的
                                    
                                     hour
                                    
                                   
                                  
                                 
                                
                               
                              
                             
                            
                           
                          
                         
                        
                       
                      
                     
                    
                   
                  
SELECT COUNT(*) FROM conditions WHERE time > NOW() - INTERVAL 12 hour;
                   https://stackoverflow.com/questions/63057183
复制Copyright © 2013 - 2024 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有