pg_reactive Example 4 -- HAVING + Window Functions

Category Leaderboard

Two simultaneous live queries with advanced SQL constructs
categories
rankings

Premium Categories

HAVING
Waiting for data...
Only shows categories where AVG(price) > $50. pg_ivm cannot handle HAVING clauses.

Product Rankings

RANK() OVER
Waiting for data...
Uses RANK() OVER (PARTITION BY category ORDER BY price DESC). pg_ivm cannot handle window functions.
This example uses HAVING and RANK() OVER -- SQL constructs that pg_ivm, Hasura, Debezium, Supabase, and ElectricSQL all fail on. Only pg_reactive delivers live deltas for these queries. When the average price drops below $50 for a category, it disappears from the left panel. Rankings re-sort automatically when prices change.
-- Connect to the database
-- docker compose exec -T db psql -U postgres -d pg_reactive_test

-- Expensive product pushes electronics avg higher, shifts rankings
INSERT INTO products (name, price, category)
  VALUES ('Gaming Laptop', 1299.99, 'electronics');

-- Cheap product might push a category below $50 threshold
INSERT INTO products (name, price, category)
  VALUES ('USB Cable', 4.99, 'electronics');

-- New category appears in both panels
INSERT INTO products (name, price, category)
  VALUES ('Standing Desk', 599.99, 'furniture');
INSERT INTO products (name, price, category)
  VALUES ('Ergonomic Chair', 299.99, 'furniture');

-- Price update shifts rankings
UPDATE products SET price = 199.99
  WHERE name = 'Headphones';