title: SQLAlchemy: Need help to translate this complex raw query to ORM (subqueries, window functions)
body: <p>Here is a postgres query that I would like to translate to sqlalchemy ORM:</p>
  
  <pre><code>SELECT
    *
  FROM
    (
      SELECT
        *, 
        date_trunc(
          'hour',
          time_obs + INTERVAL '15' MINUTE
        ) AS usedTimestamp,
        ROW_NUMBER() OVER(
          PARTITION BY icao,
          date_trunc(
            'hour',
            time_obs + INTERVAL '15' MINUTE
          )
        ORDER BY
          LEAST(
            EXTRACT(
              MINUTE
              FROM
                time_obs
            ),
            60 - EXTRACT(
              MINUTE
              FROM
                time_obs
            )
          )
        ) AS seqnum
      FROM
        metar_current
      WHERE
        icao = 'DGAA'
    ) AS dt
  WHERE
    seqnum = 1
  AND LEAST(
    ` EXTRACT(
      MINUTE
      FROM
        time_obs
    ),
    60 - EXTRACT(
      MINUTE
      FROM
        time_obs
    )
  ) &lt;= 15
  ORDER BY
    time_obs ASC
  </code></pre>
  
  <p>If it is not possible (or to difficult) to translate this to sqlalchemy ORM, then is there some way that I could query this as raw sql, but reference the resulting data using column names?</p>