-- Test 2: TimescaleDB
\set ON_ERROR_STOP on

DROP TABLE IF EXISTS sensors CASCADE;

CREATE TABLE sensors (
    time TIMESTAMPTZ NOT NULL,
    sensor_id INTEGER,
    temperature DOUBLE PRECISION
);

-- Convert to hypertable
SELECT create_hypertable('sensors', 'time');

-- Insert data
INSERT INTO sensors (time, sensor_id, temperature) VALUES 
    (NOW(), 1, 20.0), 
    (NOW() + INTERVAL '1 hour', 1, 22.0);

-- Query data
DO $$
DECLARE
    count int;
BEGIN
    SELECT count(*) INTO count FROM sensors;
    IF count != 2 THEN
        RAISE EXCEPTION 'Hypertable insert failed';
    END IF;
    RAISE NOTICE 'TimescaleDB Check: OK';
END
$$;
