0

I have a go project that connects to a postgres database. I want to delete orders over a certain number of days - I have tried doing it like this:


type SQLOrderDatabase struct {
    Connection *pgx.Conn
    logger     *logrus.Entry
}



interval := pgtype.Interval{}

_ = interval.Set(time.Second * 5)
_, err := database.Connection.Exec(ctx, "DELETE FROM store.items WHERE store.time > (now() AT TIME ZONE 'utc' - $1);", &interval)

This is using the pgx library and pgx types. However it consistently fails with this error:


Error:ERROR: operator does not exist: timestamp without time zone \u003e interval (SQLSTATE 42883)","severity":"error","

Is there anyway to use postgres intervals with go?

Adrian
  • 42,911
  • 6
  • 107
  • 99
Nespony
  • 1,253
  • 4
  • 24
  • 42

1 Answers1

0

There isn't enough context for postgres to know how you want to subtract the data passed as $1 so you need to explicitly tell it, which you can do by type casting the parameter.

(now() AT TIME ZONE 'utc' - $1::interval)
mkopriva
  • 35,176
  • 4
  • 57
  • 71