Skip to main content
Version: 0.2

Hello World

This quick start shows how to mirror a regular Postgres table to a columnstore table and run analytics on it.

1. Enable the extension​

CREATE EXTENSION pg_mooncake;

2. Create a regular Postgres table​

CREATE TABLE trades(
id BIGINT PRIMARY KEY,
symbol TEXT,
time TIMESTAMP,
price REAL
);

3. Create a columnstore mirror that stays in sync​

CALL mooncake.create_table('trades_iceberg', 'trades');

4. Insert sample data​

INSERT INTO trades VALUES
(1, 'AMD', '2024-06-05 10:00:00', 119),
(2, 'AMZN', '2024-06-05 10:05:00', 207),
(3, 'AAPL', '2024-06-05 10:10:00', 203),
(4, 'AMZN', '2024-06-05 10:15:00', 210);

5. Query the columnstore table​

SELECT AVG(price) FROM trades_iceberg WHERE symbol = 'AMZN';

Note: In pg_mooncake v0.2 all writes must go through the original Postgres table (trades). Direct inserts into the columnstore mirror (trades_iceberg) are not yet supported.