-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdb_functions.sql
54 lines (48 loc) · 915 Bytes
/
db_functions.sql
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
CREATE or REPLACE FUNCTION is_adult(dob Date)
returns boolean
language plpgsql
as
$$
DECLARE
BEGIN
if date_part('year',AGE(CURRENT_DATE,dob))>=18 then
return TRUE;
else
return FALSE;
END if;
END;
$$;
----------------------------------------------------
CREATE or REPLACE PROCEDURE error_gen()
language plpgsql
as
$$
DECLARE
BEGIN
raise exception using message = 'This is an error';
END;
$$;
CALL error_gen();
------------------------------
CREATE OR REPLACE FUNCTION contains(parent varchar(100), child varchar(100))
RETURNS BOOLEAN
LANGUAGE plpgsql
AS
$$
DECLARE
cnt int;
len int := LENGTH(child);
parentLen int := LENGTH(parent);
begin
cnt:=1;
while cnt + len <= parentLen+1 loop
--raise notice '%, %', SUBSTR(parent,cnt,len), child;
if LOWER(SUBSTR(parent,cnt,len)) = LOWER(child) then
return true;
end if;
cnt := cnt + 1;
end loop;
--raise notice 'child: %', child;
return false;
end;
$$;