0.sql 1.5 KB

12345678910111213141516171819
  1. begin;
  2. -- Создаем таблицу measurement_batch
  3. create table if not exists measurement_batch(id serial primary key, start_period timestamp, username varchar(64), pos_x numeric, pos_y numeric);
  4. -- Создаем таблицу measurement_types
  5. create table if not exists measurement_types (id serial primary key, name varchar(64));
  6. -- Создаем таблицу measurement_params
  7. create table if not exists measurement_params(id serial primary key, measurement_type_id integer references measurement_types(id), measurement_batch_id integer references measurement_batch(id), height numeric, temperature numeric, pressure numeric, wind_speed numeric, wind_direction numeric, bullet_speed numeric);
  8. -- Добавляем тестовые типы измерений
  9. insert into measurement_types(name) values ('ДМК');
  10. insert into measurement_types(name) values ('РУЖЬЕ');
  11. -- Добавляем тестовые измерения
  12. insert into measurement_batch(start_period, username, pos_x, pos_y) values(now(), 'test', 69, 42);
  13. -- Добавляем тестовые данные замеров
  14. insert into measurement_params(measurement_type_id, measurement_batch_id, height, temperature, pressure, wind_speed, wind_direction, bullet_speed) values (1, 1, 100, 15, 750, 0, 0, 0);
  15. commit;
  16. select mtypes.name, batch.start_period, batch.username, batch.pos_x, batch.pos_y, params.* from measurement_params params join measurement_batch batch on params.measurement_batch_id = batch.id join measurement_types mtypes on params.measurement_type_id = mtypes.id;