1 year ago

#355348

test-img

nrao

How to use time.Time in a postgres query?

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.

postgresql

go

pq

0 Answers

Your Answer

Accepted video resources