Skip to content

Commit f0f8b2d

Browse files
authored
Merge pull request #1525 from joto/fix-serial-column
Only create create_only columns in final table
2 parents 7e17356 + ad5de77 commit f0f8b2d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/flex-table.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ flex_table_t::build_sql_create_table(table_type ttype,
108108
ttype == table_type::interim ? "UNLOGGED" : "", table_name);
109109

110110
for (auto const &column : m_columns) {
111-
sql += column.sql_create();
111+
// create_only columns are only created in permanent, not in the
112+
// interim tables
113+
if (ttype == table_type::permanent || !column.create_only()) {
114+
sql += column.sql_create();
115+
}
112116
}
113117

114118
assert(sql.back() == ',');
@@ -214,8 +218,9 @@ void table_connection_t::stop(bool updateable, bool append)
214218
m_db_connection->exec(table().build_sql_create_table(
215219
flex_table_t::table_type::permanent, table().full_tmp_name()));
216220

217-
std::string sql = "INSERT INTO {} SELECT * FROM {}"_format(
218-
table().full_tmp_name(), table().full_name());
221+
std::string const columns = table().build_sql_column_list();
222+
std::string sql = "INSERT INTO {} ({}) SELECT {} FROM {}"_format(
223+
table().full_tmp_name(), columns, columns, table().full_name());
219224

220225
auto const postgis_version = get_postgis_version(*m_db_connection);
221226

0 commit comments

Comments
 (0)