-- @param {String} $1:regionCode
-- @param {DateTime} $2:startDate
-- @param {DateTime} $3:endDate
SELECT
  d.day AS timestamp,
  d.avg_price AS price_mwh,
  d.avg_demand AS demand_mw,
  r.code AS region_code,
  r.name AS region_name
FROM electricity_prices_daily d
JOIN grid_regions r ON d.region_id = r.id
WHERE r.code = $1
  AND d.day BETWEEN $2 AND $3
ORDER BY d.day ASC
