clickhouse-activerecord icon indicating copy to clipboard operation
clickhouse-activerecord copied to clipboard

Support for Materialized columns

Open AlexKichkailo opened this issue 1 year ago • 2 comments

In ClickHouse, it is possible to define materialized columns for a table.

Is there any way to create a materialized column using create_table?

I imagine the syntax could be similar to the syntax for column default. something like

t.boolean :a
t.boolean :b
t.boolean :c
t.boolean :materialized_column,  materialize: -> { 'a OR b OR c' }

AlexKichkailo avatar Mar 22 '24 18:03 AlexKichkailo

You can try https://github.com/PNixx/clickhouse-activerecord/issues/55#issuecomment-939715510

PNixx avatar Mar 25 '24 13:03 PNixx

One idea @PNixx --It would be nice to include a way and an example of a plain SQL migration defined in a migrations up and down method using the underlying connection to create a materialized view. I imagine the connection is probably available, although I don't know if I saw any examples of running queries directly.

I'm using a materialized view with a group_by and toStartOfInterval with some data for graphs. This would be a difficult migration to write through ActiveRecord, but it would be nice to keep even plain SQL migrations in the set of migrations to build the database.

ericbeland avatar May 10 '24 12:05 ericbeland