Skip to content

Commit c82db91

Browse files
committed
Bugfix: Flex backend tables w/o geometry were unlogged
Fixes #1141
1 parent b59e10e commit c82db91

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

flex-config/geometries.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ tables.boundaries = osm2pgsql.define_relation_table('boundaries', {
4545
{ column = 'geom', type = 'multilinestring' },
4646
})
4747

48+
-- Tables don't have to have a geometry column. This one will only collect
49+
-- all the names of pubs but without any location information.
50+
tables.pubs = osm2pgsql.define_node_table('pubs', {
51+
{ column = 'name', type = 'text' }
52+
})
53+
4854
-- Helper function to remove some of the tags we usually are not interested in.
4955
-- Returns true if there are no tags left.
5056
function clean_tags(tags)
@@ -105,6 +111,12 @@ function osm2pgsql.process_node(object)
105111
tables.pois:add_row({
106112
tags = object.tags
107113
})
114+
115+
if object.tags.amenity == 'pub' then
116+
tables.pubs:add_row({
117+
name = object.tags.name
118+
})
119+
end
108120
end
109121

110122
function osm2pgsql.process_way(object)

src/flex-table.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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());

src/flex-table.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ class flex_table_t
2121
{
2222

2323
public:
24+
25+
/**
26+
* Table creation type: interim tables are created as UNLOGGED and with
27+
* autovacuum disabled.
28+
*/
29+
enum class table_type {
30+
interim,
31+
permanent
32+
};
33+
2434
flex_table_t(std::string const &name, int srid) : m_name(name), m_srid(srid)
2535
{}
2636

@@ -91,7 +101,8 @@ class flex_table_t
91101

92102
std::string build_sql_prepare_get_wkb() const;
93103

94-
std::string build_sql_create_table(bool final_table) const;
104+
std::string build_sql_create_table(table_type ttype,
105+
std::string const &table_name) const;
95106

96107
std::string build_sql_column_list() const;
97108

0 commit comments

Comments
 (0)