瀏覽代碼

HomeWork20240221

Volovikov Alexander 3 月之前
父節點
當前提交
fe131b120d

+ 20 - 0
_Infra/scripts/20240226_step1.sql

@@ -0,0 +1,20 @@
+-- PROCEDURE: public.sp_write_log()
+
+-- DROP PROCEDURE IF EXISTS public.sp_write_log();
+
+CREATE OR REPLACE PROCEDURE public.sp_write_log(
+		in message text,
+		in data ANYELEMENT
+	)
+LANGUAGE 'plpgsql'
+AS $BODY$
+begin
+
+	if coalesce(message, '') != '' then
+		insert into public.application_log_history(started, message, data)
+		values (now(), message, row_to_json(data));
+	end if;
+	
+end;
+$BODY$;
+

+ 14 - 0
_Infra/scripts/20240226_step2.sql

@@ -0,0 +1,14 @@
+create sequence application_log_history_seq;
+create table application_log_history
+(
+	id integer not null primary key default nextval('public.application_log_history_seq'),
+	started timestamp not null,
+	message text,
+	data jsonb,
+	login varchar(100) default current_user
+);
+
+
+ --row_to_json(data)
+--SELECT * FROM jsonb_populate_record(NULL::temperature_correction, '{"calc_height_id": 1, "height": 50, "deviation": 10}'::jsonb);
+

+ 12 - 0
_Infra/scripts/20240226_step3.sql

@@ -0,0 +1,12 @@
+explain
+select * from public.measurment_input_params as t1
+inner join public.measurment_baths as t2 on t1.id = t2.measurment_input_param_id
+inner join public.employees as t3 on t3.id = t2.emploee_id
+where
+	t2.emploee_id = 10
+
+	--               ->  Seq Scan on measurment_baths t2  (cost=0.00..472.51 rows=500 width=20)
+
+	create index ix_measurment_baths_emploee_id on measurment_baths(emploee_id)
+
+	--               ->  Index Scan using ix_measurment_baths_emploee_id on measurment_baths t2  (cost=0.29..20.04 rows=500 width=20)

+ 3 - 3
_Infra/scripts/HomeWork20250214.sql

@@ -659,8 +659,8 @@ declare
 	var_temperature text;
 begin
 
-	var_pressure_value :=  public.fn_calc_header_pressure(743);
-	var_temperature_value := public.fn_calc_header_temperature(23);
+	var_pressure_value :=  round(public.fn_calc_header_pressure(743));
+	var_temperature_value := round( public.fn_calc_header_temperature(3));
 	
 	select
 		-- Дата
@@ -682,7 +682,7 @@ begin
 				else
 					''
 				end ||
-				(var_temperature_value::int)::text
+				(abs(var_temperature_value)::int)::text
 			, 2,'0') as "TT"
 		into
 			var_period, var_height, var_pressure, var_temperature;

+ 8 - 8
_Infra/scripts/HomeWork20250221.sql

@@ -92,7 +92,7 @@ create table employees
     id integer primary key not null,
 	name text,
 	birthday timestamp ,
-	military_rank_id integer
+	military_rank_id integer not null
 );
 
 insert into employees(id, name, birthday,military_rank_id )  
@@ -187,8 +187,8 @@ raise notice 'Создание общих справочников и напол
 
 create table calc_temperature_correction
 (
-   temperature numeric(8,2) primary key,
-   correction numeric(8,2)
+   temperature numeric(8,2) not null primary key,
+   correction numeric(8,2) not null
 );
 
 insert into public.calc_temperature_correction(temperature, correction)
@@ -254,9 +254,9 @@ values (1, 'Заголовок для Таблицы № 2 (ДМК)', array[0, 1
 create sequence calc_height_correction_seq;
 create table calc_height_correction
 (
-	id integer primary key default nextval('public.calc_height_correction_seq'),
+	id integer primary key not null default nextval('public.calc_height_correction_seq'),
 	height integer not null,
-	measurment_type_id integer
+	measurment_type_id integer not null
 );
 
 insert into calc_height_correction(height, measurment_type_id)
@@ -268,9 +268,9 @@ values(200,1),(400,1),(800,1),(1200,1),(1600,1),(2000,1),(2400,1),(3000,1),(4000
 create sequence calc_temperature_height_correction_seq;
 create table calc_temperature_height_correction
 (
-	id integer primary key default nextval('public.calc_temperature_height_correction_seq'),
-	calc_height_id integer,
-	calc_temperature_header_id integer,
+	id integer primary key not null default nextval('public.calc_temperature_height_correction_seq'),
+	calc_height_id integer not null,
+	calc_temperature_header_id integer not null,
 	positive_values numeric[],
 	negative_values numeric[]
 );