diff --git a/src/flex-table.cpp b/src/flex-table.cpp index 370499197..6dff56a4e 100644 --- a/src/flex-table.cpp +++ b/src/flex-table.cpp @@ -281,12 +281,12 @@ static void enable_check_trigger(pg_conn_t const &db_connection, void table_connection_t::start(pg_conn_t const &db_connection, bool append) { if (!append) { - db_connection.exec("DROP TABLE IF EXISTS {} CASCADE", - table().full_name()); + drop_table_if_exists(db_connection, table().schema(), table().name()); } // These _tmp tables can be left behind if we run out of disk space. - db_connection.exec("DROP TABLE IF EXISTS {}", table().full_tmp_name()); + drop_table_if_exists(db_connection, table().schema(), + table().name() + "_tmp"); if (!append) { db_connection.exec(table().build_sql_create_table( diff --git a/src/middle-pgsql.cpp b/src/middle-pgsql.cpp index f9759840e..e2f1df1ea 100644 --- a/src/middle-pgsql.cpp +++ b/src/middle-pgsql.cpp @@ -148,10 +148,7 @@ void middle_pgsql_t::table_desc::drop_table( util::timer_t timer; log_info("Dropping table '{}'", name()); - - auto const qual_name = qualified_name(schema(), name()); - db_connection.exec("DROP TABLE IF EXISTS {}", qual_name); - + drop_table_if_exists(db_connection, schema(), name()); log_info("Table '{}' dropped in {}", name(), util::human_readable_duration(timer.stop())); } @@ -1318,8 +1315,7 @@ static void table_setup(pg_conn_t const &db_connection, middle_pgsql_t::table_desc const &table) { log_debug("Setting up table '{}'", table.name()); - auto const qual_name = qualified_name(table.schema(), table.name()); - db_connection.exec("DROP TABLE IF EXISTS {} CASCADE", qual_name); + drop_table_if_exists(db_connection, table.schema(), table.name()); table.create_table(db_connection); } diff --git a/src/pgsql-helper.cpp b/src/pgsql-helper.cpp index b438594e4..43e2e1241 100644 --- a/src/pgsql-helper.cpp +++ b/src/pgsql-helper.cpp @@ -7,9 +7,11 @@ * For a full list of authors see the git log. */ +#include "pgsql-helper.hpp" + #include "format.hpp" #include "pgsql.hpp" -#include "pgsql-helper.hpp" +#include "pgsql-capabilities.hpp" #include @@ -73,3 +75,10 @@ void analyze_table(pg_conn_t const &db_connection, std::string const &schema, auto const qual_name = qualified_name(schema, name); db_connection.exec("ANALYZE {}", qual_name); } + +void drop_table_if_exists(pg_conn_t const &db_connection, + std::string const &schema, std::string const &name) +{ + db_connection.exec("DROP TABLE IF EXISTS {} CASCADE", + qualified_name(schema, name)); +} diff --git a/src/pgsql-helper.hpp b/src/pgsql-helper.hpp index 7a38ee753..4e0894b35 100644 --- a/src/pgsql-helper.hpp +++ b/src/pgsql-helper.hpp @@ -40,4 +40,7 @@ void drop_geom_check_trigger(pg_conn_t const &db_connection, void analyze_table(pg_conn_t const &db_connection, std::string const &schema, std::string const &name); +void drop_table_if_exists(pg_conn_t const &db_connection, + std::string const &schema, std::string const &name); + #endif // OSM2PGSQL_PGSQL_HELPER_HPP diff --git a/src/table.cpp b/src/table.cpp index 64c71d8af..0dc78826e 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -83,21 +83,22 @@ void table_t::start(connection_params_t const &connection_params, connect(); log_info("Setting up table '{}'", m_target->name()); - auto const qual_name = qualified_name(m_target->schema(), m_target->name()); - auto const qual_tmp_name = - qualified_name(m_target->schema(), m_target->name() + "_tmp"); // we are making a new table if (!m_append) { - m_db_connection->exec("DROP TABLE IF EXISTS {} CASCADE", qual_name); + drop_table_if_exists(*m_db_connection, m_target->schema(), + m_target->name()); } // These _tmp tables can be left behind if we run out of disk space. - m_db_connection->exec("DROP TABLE IF EXISTS {}", qual_tmp_name); + drop_table_if_exists(*m_db_connection, m_target->schema(), + m_target->name() + "_tmp"); //making a new table if (!m_append) { //define the new table + auto const qual_name = + qualified_name(m_target->schema(), m_target->name()); auto sql = fmt::format("CREATE UNLOGGED TABLE {} (osm_id int8,", qual_name);