In CartoDB you can do this as two steps, first the SQL and then the creation of a new table from the result.
That should give you a two column result, you wont be able to map it yet. You may also run into a problem if you don't close your polygon. Meaning, you need the polygon to end on the same point it started (in the list of vertices). If that is the case, you could fix it with,
(SELECT ST_StartPoint(the_geom) FROM tablename
WHERE some_id_of_polygon = t.some_id_of_polygon LIMIT 1
Create a new table
Now, you should be able to create a new table by clicking the link that appears in your table view Create new table from Query. If you don't see it right away, click the dropdown Options in the upper right and you should see it in there.
Your new table should be a set of polygons and your some_id_of_polygon