Probably, you can do something like:
create table test4 (date Date, val UInt64) engine = MergeTree(date, (date), 8192);
insert into test4 values (today(), 0);
select * from test4;
┌───────date─┬─val─┐
│ 2017-09-27 │ 0 │
└────────────┴─────┘
insert into test4 select today(), (select count(*) from test4) + number from system.numbers limit 5;
select * from test4;
┌───────date─┬─val─┐
│ 2017-09-27 │ 0 │
└────────────┴─────┘
┌───────date─┬─val─┐
│ 2017-09-27 │ 1 │
│ 2017-09-27 │ 2 │
│ 2017-09-27 │ 3 │
│ 2017-09-27 │ 4 │
│ 2017-09-27 │ 5 │
└────────────┴─────┘
insert into test4 select today(), (select count(*) from test4) + number from system.numbers limit 5;
select * from test4;
┌───────date─┬─val─┐
│ 2017-09-27 │ 1 │
│ 2017-09-27 │ 2 │
│ 2017-09-27 │ 3 │
│ 2017-09-27 │ 4 │
│ 2017-09-27 │ 5 │
└────────────┴─────┘
┌───────date─┬─val─┐
│ 2017-09-27 │ 6 │
│ 2017-09-27 │ 7 │
│ 2017-09-27 │ 8 │
│ 2017-09-27 │ 9 │
│ 2017-09-27 │ 10 │
└────────────┴─────┘
┌───────date─┬─val─┐
│ 2017-09-27 │ 0 │
└────────────┴─────┘
But, this approach isn't good enough. For example, if one insert starts when other isn't finished, count(*) will return old value, and ids will overlap.
Do you really need AUTO_INCREMENT? Date or DateTime value may be enough to distinguish rows.
среда, 27 сентября 2017 г., 14:23:55 UTC+3 пользователь James Wang написал: