@@ -494,6 +494,32 @@ static void write_json(json_writer_type *writer, lua_State *lua_state,
494494 }
495495}
496496
497+ static bool is_compatible (geom::geometry_t const &geom,
498+ table_column_type type) noexcept
499+ {
500+ switch (type) {
501+ case table_column_type::geometry:
502+ return true ;
503+ case table_column_type::point:
504+ return geom.is_point ();
505+ case table_column_type::linestring:
506+ return geom.is_linestring ();
507+ case table_column_type::polygon:
508+ return geom.is_polygon ();
509+ case table_column_type::multipoint:
510+ return geom.is_point () || geom.is_multipoint ();
511+ case table_column_type::multilinestring:
512+ return geom.is_linestring () || geom.is_multilinestring ();
513+ case table_column_type::multipolygon:
514+ return geom.is_polygon () || geom.is_multipolygon ();
515+ case table_column_type::geometrycollection:
516+ return geom.is_collection ();
517+ default :
518+ break ;
519+ }
520+ return false ;
521+ }
522+
497523void output_flex_t::write_column (
498524 db_copy_mgr_t <db_deleter_by_type_and_id_t > *copy_mgr,
499525 flex_table_column_t const &column)
@@ -673,6 +699,12 @@ void output_flex_t::write_column(
673699 auto const *const geom = unpack_geometry (lua_state (), -1 );
674700 if (geom && !geom->is_null ()) {
675701 auto const type = column.type ();
702+ if (!is_compatible (*geom, type)) {
703+ throw std::runtime_error{
704+ " Geometry data for geometry column '{}'"
705+ " has the wrong type ({})." _format (
706+ column.name (), geometry_type (*geom))};
707+ }
676708 bool const wrap_multi =
677709 (type == table_column_type::multipoint ||
678710 type == table_column_type::multilinestring ||
0 commit comments