How to select same number of data points over different time ranges Grafana is querying our postgres database using this SELECT statement:

SELECT
  tstamp AS "time"
  dvalue AS "weight"
FROM tablename
WHERE
  description = "exp_weight" AND
  tstamp BETWEEN 'time1' AND 'time2'
ORDER BY 
  tstamp


How can I code this such that I'm displaying the same number of data points even if my time intervals are different (ex. display 1,000 data points in the last hour or display 1,000 data points in the last month).
One simple solution is:

SELECT *
FROM (SELECT tstamp AS time,
             dvalue AS weight
      FROM tablename
      WHERE description = 'exp_weight'
        AND tstamp BETWEEN 'time1' AND 'time2'
      ORDER BY random()
      LIMIT 1000
     ) AS q
ORDER BY time;


Explanation: The dataset is shuffled randomly, tgen the first 1000 values are taken and the result ordered by time. The subquery is just a syntactical necessity.