@@ -222,6 +222,27 @@ std::string flex_table_t::build_sql_column_list() const
222222 return joiner ();
223223}
224224
225+ std::string flex_table_t::build_sql_copy_condition () const
226+ {
227+ assert (!m_columns.empty ());
228+
229+ std::string checks;
230+
231+ for (auto const &column : m_columns) {
232+ if (column.is_geometry_column () && column.needs_isvalid ()) {
233+ checks.append (fmt::format (
234+ R"( ("{0}" IS NULL OR ST_IsValid("{0}")) AND )" , column.name ()));
235+ }
236+ }
237+
238+ if (!checks.empty ()) {
239+ // remove last " AND "
240+ checks.resize (checks.size () - 5 );
241+ }
242+
243+ return checks;
244+ }
245+
225246std::string flex_table_t::build_sql_create_id_index () const
226247{
227248 if (m_primary_key_index) {
@@ -269,30 +290,6 @@ bool flex_table_t::with_id_cache() const noexcept { return m_with_id_cache; }
269290
270291namespace {
271292
272- void enable_check_trigger (pg_conn_t const &db_connection,
273- flex_table_t const &table)
274- {
275- std::string checks;
276-
277- for (auto const &column : table.columns ()) {
278- if (column.is_geometry_column () && column.needs_isvalid ()) {
279- checks.append (fmt::format (
280- R"( (NEW."{0}" IS NULL OR ST_IsValid(NEW."{0}")) AND )" ,
281- column.name ()));
282- }
283- }
284-
285- if (checks.empty ()) {
286- return ;
287- }
288-
289- // remove last " AND "
290- checks.resize (checks.size () - 5 );
291-
292- create_geom_check_trigger (db_connection, table.schema (), table.name (),
293- checks);
294- }
295-
296293} // anonymous namespace
297294
298295void table_connection_t::start (pg_conn_t const &db_connection,
@@ -311,8 +308,6 @@ void table_connection_t::start(pg_conn_t const &db_connection,
311308 table ().cluster_by_geom () ? flex_table_t ::table_type::interim
312309 : flex_table_t ::table_type::permanent,
313310 table ().full_name ()));
314-
315- enable_check_trigger (db_connection, table ());
316311 }
317312
318313 table ().prepare (db_connection);
@@ -328,11 +323,6 @@ void table_connection_t::stop(pg_conn_t const &db_connection, bool updateable,
328323 }
329324
330325 if (table ().cluster_by_geom ()) {
331- if (table ().geom_column ().needs_isvalid ()) {
332- drop_geom_check_trigger (db_connection, table ().schema (),
333- table ().name ());
334- }
335-
336326 log_info (" Clustering table '{}' by geometry..." , table ().name ());
337327
338328 db_connection.exec (table ().build_sql_create_table (
@@ -354,10 +344,6 @@ void table_connection_t::stop(pg_conn_t const &db_connection, bool updateable,
354344 db_connection.exec (R"( ALTER TABLE {} RENAME TO "{}")" ,
355345 table ().full_tmp_name (), table ().name ());
356346 m_id_index_created = false ;
357-
358- if (updateable) {
359- enable_check_trigger (db_connection, table ());
360- }
361347 }
362348
363349 if (table ().indexes ().empty ()) {
0 commit comments