@@ -89,13 +89,13 @@ std::string flex_table_t::build_sql_prepare_get_wkb() const
8989 return " PREPARE get_wkb(bigint) AS SELECT ''" ;
9090}
9191
92- std::string flex_table_t::build_sql_create_table (bool final_table) const
92+ std::string flex_table_t::build_sql_create_table (table_type ttype,
93+ std::string const &table_name) const
9394{
9495 assert (!m_columns.empty ());
9596
9697 std::string sql = " CREATE {} TABLE IF NOT EXISTS {} (" _format (
97- final_table ? " " : " UNLOGGED" ,
98- final_table ? full_tmp_name () : full_name ());
98+ ttype == table_type::interim ? " UNLOGGED" : " " , table_name);
9999
100100 for (auto const &column : m_columns) {
101101 sql += column.sql_create (m_srid);
@@ -104,7 +104,7 @@ std::string flex_table_t::build_sql_create_table(bool final_table) const
104104 assert (sql.back () == ' ,' );
105105 sql.back () = ' )' ;
106106
107- if (!final_table ) {
107+ if (ttype == table_type::interim ) {
108108 sql += " WITH (autovacuum_enabled = off)" ;
109109 }
110110
@@ -166,7 +166,11 @@ void table_connection_t::start(bool append)
166166 m_db_connection->exec (
167167 " CREATE SCHEMA IF NOT EXISTS \" {}\" " _format (table ().schema ()));
168168 }
169- m_db_connection->exec (table ().build_sql_create_table (false ));
169+
170+ m_db_connection->exec (table ().build_sql_create_table (
171+ table ().has_geom_column () ? flex_table_t ::table_type::interim
172+ : flex_table_t ::table_type::permanent,
173+ table ().full_name ()));
170174 } else {
171175 // check the columns against those in the existing table
172176 auto const res = m_db_connection->query (
@@ -212,7 +216,8 @@ void table_connection_t::stop(bool updateable, bool append)
212216 // because they say nothing about the validity of the geometry in OSM.
213217 m_db_connection->exec (" SET client_min_messages = WARNING" );
214218
215- m_db_connection->exec (table ().build_sql_create_table (true ));
219+ m_db_connection->exec (table ().build_sql_create_table (
220+ flex_table_t ::table_type::permanent, table ().full_tmp_name ()));
216221
217222 std::string sql = " INSERT INTO {} SELECT * FROM {}" _format (
218223 table ().full_tmp_name (), table ().full_name ());
0 commit comments