Harman
Harman

Reputation: 539

postgresql ERROR: syntax error at or near "CONCAT"

i am trying to fetch users list who older than and between 20 to 60 minute randomly. here is my query

SELECT * 
FROM  t_users 
WHERE create_time <= NOW() -  INTERVAL CONCAT(floor(random()* (60-20 + 1) + 20),' minutes'); 

it's giving me error ERROR: syntax error at or near "CONCAT"

Upvotes: 0

Views: 572

Answers (1)

user330315
user330315

Reputation:

You can't use concat() like that to create an interval. The easiest solution is to use make_interval:

WHERE create_time <= NOW() - make_interval(mins => (floor(random()* (60-20 + 1) + 20))::int )

Upvotes: 1

Related Questions