-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcedures.sql
More file actions
69 lines (64 loc) · 2.22 KB
/
Procedures.sql
File metadata and controls
69 lines (64 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
create or replace function hide_control_form(inText text)
returns text as $$
declare
result text := '';
begin
if inText = 'Экзамен' then result := 'Экзамен';
else result = 'Зачет';
end if;
return result;
end;
$$ language plpgsql;
create or replace function hide_email(inText text)
returns text as $$
declare
result text := '';
flag boolean := true;
n int := 0;
begin
n = position('@' in inText);
for i in 1 .. n-1 by 1
loop
result = concat(result, '#');
end loop;
result = concat(result, right(inText, char_length(inText) - n + 1));
return result;
end;
$$ language plpgsql;
/*
Вернуть группы, в которых преподаватель ведет семинары и соответствующие предметы
*/
drop procedure if exists teaching_groups_by_teacher_id(teacher_id_ int);
create or replace procedure teaching_groups_by_teacher_id(teacher_id_ int)
language sql as $$
drop table if exists university_db.teachers_groups;
create table university_db.teachers_groups as
select group_id, discipline_name
from university_db."Seminars" as S
where S.teacher_id = teacher_id_;
$$;
call teaching_groups_by_teacher_id(1);
select *
from university_db.teachers_groups;
/*
Вернуть студенту его предметы и формы их контроля по student_id
*/
drop procedure if exists get_students_disciplines(student_id_ int);
create or replace procedure get_students_disciplines(student_id_ int)
language sql as $$
drop table if exists university_db.students_disciplines;
create table university_db.students_disciplines as
with group_disciplines
as (
select discipline_name
from university_db."Seminars" as S
where S.group_id = (select group_id from university_db."Students" as St where St.student_id = student_id_)
)
select D.discipline_name, control_form
from university_db."Disciplines" as D
inner join group_disciplines as G
on D.discipline_name = G.discipline_name;
$$;
call get_students_disciplines(26);
select *
from university_db.students_disciplines;