CREATE TABLE device_t (
    id SERIAL NOT NULL PRIMARY KEY,
    device_id VARCHAR(32) NOT NULL UNIQUE,
    label VARCHAR(16) NOT NULL
);

CREATE TABLE sensor_t (
    id SERIAL NOT NULL PRIMARY KEY,
    address NUMERIC NOT NULL UNIQUE,
    label VARCHAR(5) NOT NULL,
    index SMALLINT NOT NULL,
    device INTEGER NOT NULL REFERENCES device_t(id),
    unique (label, device),
    unique (index, device)
);

CREATE TABLE measurement_t (
    time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
    device_name VARCHAR(16) NOT NULL,
    sensor_name VARCHAR(5) NOT NULL,
    temperature DOUBLE PRECISION
);

SELECT create_hypertable('measurement_t', 'time');

insert into device_t (device_id, label) values('eui-43fa12f400006c88', 'badesee');
insert into sensor_t (address, label, index, device) 
  values (13258914387362694952, '0,5m ', 0, 1), 
         (12970366982842161448, '2,0m ', 1, 1), 
         (10664523975231507496, '3,0m ', 2, 1), 
         (15276209993662477608, '4,0m ', 3, 1);

select d.label as device_label,
       s.label as label,
       s.address as address,
       s.index as index
  from device_t d, sensor_t s
  where d.id = s.device;
  