Materialized view error

30 views
Skip to first unread message

Oleksiy Illyashov

unread,
Dec 9, 2022, 11:27:04 PM12/9/22
to ClickHouse
Hi, 
trying to create MV to get latest record values, but getting error messages for any type of fields. Code sample:

CREATE TABLE from_table
(
    id UInt32,
    version UInt32,
    value Int32
)
ENGINE =  MergeTree()
PARTITION BY tuple()
order by id;

insert into from_table values (1, 1, 0);
insert into from_table values (1, 2, 5);
insert into from_table values (1, 3, 3);

CREATE TABLE to_table
(
    id UInt32,
    value AggregateFunction(argMax, UInt32, UInt32)
)
ENGINE = AggregatingMergeTree
PARTITION BY tuple()
order by id;

CREATE MATERIALIZED VIEW to_table_mv
to to_table
AS
SELECT id, argMaxState(value,version) as value
from from_table
group by id;


last statement( CREATE MATERIALIZED VIEW to_table_mv ...)  generates error message:

SQL Error [70] [07000]: Code: 70. DB::Exception: Conversion from AggregateFunction(argMax, Int32, UInt32) to AggregateFunction(argMax, UInt32, UInt32) is not supported: while converting source column value to destination column value. (CANNOT_CONVERT_TYPE) (version 22.12.1.392 (official build))

Any ideas?

Thanks a lot,
Alex

Derek Chia

unread,
Dec 11, 2022, 9:41:15 PM12/11/22
to ClickHouse
Change `value AggregateFunction(argMax, UInt32, UInt32)` to value `AggregateFunction(argMax, Int32, UInt32)` since your value column is of Int32 type.

Oleksiy Illyashov

unread,
Dec 12, 2022, 11:53:01 AM12/12/22
to ClickHouse
thanks a lot, now it works!
Reply all
Reply to author
Forward
0 new messages