skip to Main Content

I have a problem to make a query for view data in postgresql. I want to view data with 2 condition :

  1. where employeeId
  2. and between daterange

Heres my Query:

Select * 
from employee 
where employeeId = 3 
  and date(created_at) = between '2022-08-29' and '2022-08-31'

I have run that query but show error:

Reason:

SQL Error [42601]: ERROR: syntax error at or near "date" Position: 1`

The type data of column created_at is timestamp.
My questions is: What is correct query for view data from that conditions?

2

Answers


  1. You can use arithmetic operation

    Select * 
    from employee 
    where employeeId = 3 
      and created_at>='2022-08-29' 
      and created_at< '2022-09-01'
    
    Login or Signup to reply.
  2. Remove the = operator from your query, the BETWEEN does not require the =

    Select * from employee where employeeId = 3 and date(created_at)  between '2022-08-29' and '2022-08-31' 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search