Add some useful sql scripts

This commit is contained in:
Фролов 2022-02-22 11:03:27 +05:00
parent 29845aa36a
commit 5d8afcd907
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,9 @@
select t_cluster.caption as cluster,
t_well.caption as well,
t_well.id_telemetry
from t_cluster
join t_well on t_well.id_cluster = t_cluster.id
where t_cluster.caption in ('82', 'ê50 Á', 'ê8', '6 A') and t_well.id_telemetry is not null
order by cluster , well
\copy (select "date", "mode", well_depth, bit_depth, hook_weight, hook_weight_idle, axial_load, block_speed, block_position, rotor_speed, rotor_torque, flow, flow_idle, pressure, pressure_idle from t_telemetry_data_saub where id_telemetry = 137) to '/home/asb/export/dump_c_82_w_2533_t_137.csv' DELIMITER ';' CSV header;

View File

@ -0,0 +1,36 @@
select t_cluster.caption as cluster,
t_well.caption as well,
t_well.id_telemetry
from t_cluster
join t_well on t_well.id_cluster = t_cluster.id
where t_cluster.caption in ('82', 'ê50 Á', 'ê8', '6 A') and t_well.id_telemetry is not null
order by cluster , well
select * from t_telemetry_event
where id_telemetry = 94;
select * from t_telemetry_message t_tm
where id_telemetry = 94;
select
date,
well_depth,
t_te.id_event,
t_te.message_template,
arg0 as old_value,
arg1 as new_value
from t_telemetry_message t_tm
left join (select * from t_telemetry_event where id_telemetry = 94) t_te
on t_te.id_event = t_tm.id_event
where t_tm.id_telemetry = 94
order by date;
select *
from t_telemetry_data_saub
where id_telemetry = 94;
select *
from t_telemetry_data_saub
where id_telemetry = 94
window w as (PARTITION BY id_telemetry order by date)

View File

@ -0,0 +1,10 @@
create database postgres;
create schema public;
CREATE EXTENSION IF NOT EXISTS timescaledb;
SELECT timescaledb_pre_restore();
\! pg_restore -Fc -d postgres dump_2022-01-11.bak
SELECT timescaledb_post_restore();