I improved my query for all the steps in San Francisco, by narrowing it down to steps that are really just in the city of SF itself and not whatever happens to be in the OSM Metro import I have in my database.
First I had to find where in the database was the actual boundary of San Francisco:
select name, * from planet_osm_polygon where boundary = 'administrative';
Visually inspecting that list turns up OSM_ID -111968, San Francisco. Below is a quick drawing of that polygon in OSM. It’s not quite correct; all the water is fine, but it leaves out the Farallons and includes a tiny bit of Alameda and Angel Island. Still, close enough.
Then it’s just a matter of doing the geographic intersection. This query makes me scratch my SQL head a little bit, I cribbed it from the PostGIS book, but it runs pretty fast. Much slower if you try this intersection on all the roads in the SF Metro.
select planet_osm_line.name, round(ST_Length(planet_osm_line.way)) as meters, planet_osm_line.osm_id from planet_osm_line inner join planet_osm_polygon on ST_Intersects(planet_osm_line.way, planet_osm_polygon.way) where planet_osm_polygon.osm_id = '-111968' and planet_osm_line.highway = 'steps' order by meters desc;
And here we go, 366 stairs.