<p>One of the following command seem to fail:</p>

<pre><code>        pgsql_exec_simple(sql_conn, PGRES_COMMAND_OK, (fmt("CREATE TABLE %1%_tmp %2% AS SELECT * FROM %1% ORDER BY CASE WHEN ST_IsEmpty(way) THEN NULL ELSE ST_GeoHash(ST_Transform(ST_Envelope(way),4326),10) END") % name % (table_space ? "TABLESPACE " + table_space.get() : "")).str());
        pgsql_exec_simple(sql_conn, PGRES_COMMAND_OK, (fmt("DROP TABLE %1%") % name).str());
        pgsql_exec_simple(sql_conn, PGRES_COMMAND_OK, (fmt("ALTER TABLE %1%_tmp RENAME TO %1%") % name).str());
        // Re-add constraints if on 1.x. 2.0 has typemod, and they automatically come with CREATE TABLE AS
        pgsql_exec_simple(sql_conn, PGRES_TUPLES_OK, (fmt("SELECT CASE WHEN PostGIS_Lib_Version() LIKE '1.%%' THEN Populate_Geometry_Columns('%1%'::regclass) ELSE 1 END;") % name).str());
</code></pre>

<p>If the base is still in that sate you can try to execute manually</p>

<pre><code>CREATE TABLE planet_osm_polygon_tmp AS SELECT * FROM planet_osm_polygon ORDER BY CASE WHEN ST_IsEmpty(way) THEN NULL ELSE ST_GeoHash(ST_Transform(ST_Envelope(way),4326),10) END
DROP TABLE planet_osm_polygon
ALTER TABLE planet_osm_polygon_tmp RENAME TO planet_osm_polygon
SELECT CASE WHEN PostGIS_Lib_Version() LIKE '1.%%' THEN Populate_Geometry_Columns('planet_osm_polygon'::regclass) ELSE 1 END;"
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/openstreetmap/osm2pgsql/issues/494#issuecomment-154089107">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AD2-7iRHnQ6vXpcvyiJ4Ybpo9FXh6gxNks5pC2omgaJpZM4GbsAQ.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/openstreetmap/osm2pgsql/issues/494#issuecomment-154089107"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>