How to use time.Time in a postgres query?

360 views Asked by At

I am using pq library in golang for postgres queries. I want to pass timestamp in the query string.

Ex. query = 'SELECT \* FROM table WHERE ts \<= NOW() - interval '5 seconds''

Instead of NOW() ...can I pass a timestamp?

Ex.

t=time.Now()

query = 'SELECT \* FROM table WHERE ts \<= t- interval '5 seconds''

I tried formatting the timestamp and using arguments to pass the timestamp but getting errors.

0

There are 0 answers