PNixx / clickhouse-activerecord

A Ruby database ActiveRecord driver for ClickHouse
MIT License
198 stars 100 forks source link

Support for Materialized columns #127

Open AlexKichkailo opened 7 months ago

AlexKichkailo commented 7 months ago

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' }
PNixx commented 7 months ago

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

ericbeland commented 5 months ago

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.