1

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.

eglease
  • 2,445
  • 11
  • 18
  • 28
nrao
  • 31
  • 1
  • 2
    You can pass a `time.Time` directly as value to a prepared statement https://stackoverflow.com/questions/47758359/how-to-store-golang-time-time-in-postgresql-timestamp – Dylan Reimerink Mar 30 '22 at 16:43
  • 1
    Does this answer your question? [How to store Golang time.time in Postgresql timestamp?](https://stackoverflow.com/questions/47758359/how-to-store-golang-time-time-in-postgresql-timestamp) – Corey Ogburn Mar 30 '22 at 16:43

0 Answers0