@@ -323,6 +323,10 @@ template <typename T>
323323void pgsql_parse_json_tags (char const *string, osmium::memory::Buffer *buffer,
324324 T *obuilder)
325325{
326+ if (*string == ' \0 ' ) { // NULL
327+ return ;
328+ }
329+
326330 auto const tags = nlohmann::json::parse (string);
327331 if (!tags.is_object ()) {
328332 throw std::runtime_error{" Database format for tags invalid." };
@@ -439,6 +443,10 @@ template <typename T>
439443void pgsql_parse_json_members (char const *string,
440444 osmium::memory::Buffer *buffer, T *obuilder)
441445{
446+ if (*string == ' \0 ' ) { // NULL
447+ return ;
448+ }
449+
442450 osmium::builder::RelationMemberListBuilder builder{*buffer, obuilder};
443451 member_list_json_builder parser{&builder};
444452 nlohmann::json::sax_parse (string, &parser);
@@ -613,6 +621,10 @@ void middle_pgsql_t::copy_attributes(osmium::OSMObject const &obj)
613621void middle_pgsql_t::copy_tags (osmium::OSMObject const &obj)
614622{
615623 if (m_store_options.db_format == 2 ) {
624+ if (obj.tags ().empty ()) {
625+ m_db_copy.add_null_column ();
626+ return ;
627+ }
616628 json_writer_t writer;
617629 tags_to_json (obj.tags (), &writer);
618630 m_db_copy.add_column (writer.json ());
@@ -1464,7 +1476,7 @@ static table_sql sql_for_nodes_format2(middle_pgsql_options const &options)
14641476 " lat int4 NOT NULL,"
14651477 " lon int4 NOT NULL,"
14661478 " {attribute_columns_definition}"
1467- " tags jsonb NOT NULL "
1479+ " tags jsonb"
14681480 " ) {data_tablespace}" ;
14691481
14701482 sql.prepare_queries = {
@@ -1530,7 +1542,7 @@ static table_sql sql_for_ways_format2(middle_pgsql_options const &options)
15301542 " id int8 PRIMARY KEY {using_tablespace},"
15311543 " {attribute_columns_definition}"
15321544 " nodes int8[] NOT NULL,"
1533- " tags jsonb NOT NULL "
1545+ " tags jsonb"
15341546 " ) {data_tablespace}" ;
15351547
15361548 sql.prepare_queries = {" PREPARE get_way(int8) AS"
@@ -1601,7 +1613,7 @@ static table_sql sql_for_relations_format2()
16011613 " id int8 PRIMARY KEY {using_tablespace},"
16021614 " {attribute_columns_definition}"
16031615 " members jsonb NOT NULL,"
1604- " tags jsonb NOT NULL "
1616+ " tags jsonb"
16051617 " ) {data_tablespace}" ;
16061618
16071619 sql.prepare_queries = {" PREPARE get_rel(int8) AS"
0 commit comments