Forbidden to use column name more than once in insert query.

This commit is contained in:
alesapin 2019-11-08 12:57:32 +03:00
parent 4e68211879
commit 40a5cf4bb9
4 changed files with 22 additions and 1 deletions

View File

@ -188,7 +188,7 @@ Block NativeBlockInputStream::readImpl()
for (auto & col : header)
{
if (res.has(col.name))
tmp_res.insert(std::move(res.getByName(col.name)));
tmp_res.insert(res.getByName(col.name));
else
tmp_res.insert({col.type->createColumn()->cloneResized(rows), col.type, col.name});
}

View File

@ -30,6 +30,7 @@ namespace ErrorCodes
extern const int NO_SUCH_COLUMN_IN_TABLE;
extern const int READONLY;
extern const int ILLEGAL_COLUMN;
extern const int DUPLICATE_COLUMN;
}
@ -84,6 +85,8 @@ Block InterpreterInsertQuery::getSampleBlock(const ASTInsertQuery & query, const
if (!allow_materialized && !table_sample_non_materialized.has(current_name))
throw Exception("Cannot insert column " + current_name + ", because it is MATERIALIZED column.", ErrorCodes::ILLEGAL_COLUMN);
if (res.has(current_name))
throw Exception("Column " + current_name + " specified more than once", ErrorCodes::DUPLICATE_COLUMN);
res.insert(ColumnWithTypeAndName(table_sample.getByName(current_name).type, current_name));
}

View File

@ -0,0 +1,17 @@
DROP TABLE IF EXISTS sometable;
CREATE TABLE sometable (
date Date,
time Int64,
value UInt64
) ENGINE=MergeTree()
ORDER BY time;
INSERT INTO sometable (date, time, value) VALUES ('2019-11-08', 1573185600, 100);
SELECT COUNT() from sometable;
INSERT INTO sometable (date, time, value, time) VALUES ('2019-11-08', 1573185600, 100, 1573185600); -- {serverError 15}
DROP TABLE IF EXISTS sometable;