Merge
The Merge engine provides a read-only view over multiple tables matching a regex pattern.
MergeTable.ts
import { OlapTable, ClickHouseEngines } from '@514labs/moose-lib'; interface Event { eventId: string; userId: string; timestamp: number;} // Read-only view over all tables matching ^events_.*$ in the current databaseexport const allEvents = new OlapTable<Event>("all_events", { engine: ClickHouseEngines.Merge, sourceDatabase: "currentDatabase()", tablesRegexp: "^events_.*$",});Configuration Options
| Option | Description |
|---|---|
sourceDatabase | Database to scan for source tables. Accepts a literal name, currentDatabase(), or REGEXP('pattern') |
tablesRegexp | Regular expression pattern to match table names within the source database |
The database field accepts:
currentDatabase()— matches the configured database, works across dev and prod without hardcoding- Literal name (e.g.,
"analytics") — matches a specific database REGEXP('pattern')— matches multiple databases by regex
Limitations
- Read-only: INSERT operations are not supported. Cannot be used as a destination in
IngestPipeline. - No ORDER BY, PARTITION BY, or SAMPLE BY: These clauses are not supported on Merge tables.
- Self-hosted only: Not supported on ClickHouse Cloud (see supported engines).
- Other constant expressions (e.g.,
concat('a', 'b')) for source database will cause the table to be recreated on each restart. ClickHouse evaluates and stores the result (e.g.,'ab'), so the expression never matches Moose's configured value and the table is dropped and recreated every time. UsecurrentDatabase()or a literal name instead.
For more details, see the ClickHouse Merge documentation.