diff --git a/idb/postgres/postgres.go b/idb/postgres/postgres.go index 0b8ff2e7..d1e88158 100644 --- a/idb/postgres/postgres.go +++ b/idb/postgres/postgres.go @@ -575,13 +575,15 @@ func buildTransactionQuery(tf idb.TransactionFilter) (query string, whereArgs [] } if !tf.BeforeTime.IsZero() { convertedTime := tf.BeforeTime.In(time.UTC) - whereParts = append(whereParts, fmt.Sprintf("h.realtime < $%d", partNumber)) + whereParts = append(whereParts, fmt.Sprintf("t.round <= ("+ + "SELECT round from block_header WHERE realtime < $%d ORDER BY realtime DESC LIMIT 1)", partNumber)) whereArgs = append(whereArgs, convertedTime) partNumber++ } if !tf.AfterTime.IsZero() { convertedTime := tf.AfterTime.In(time.UTC) - whereParts = append(whereParts, fmt.Sprintf("h.realtime > $%d", partNumber)) + whereParts = append(whereParts, fmt.Sprintf("t.round >= ("+ + "SELECT round from block_header WHERE realtime > $%d ORDER BY realtime ASC LIMIT 1)", partNumber)) whereArgs = append(whereArgs, convertedTime) partNumber++ }