-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2021.01.20.sql
78 lines (67 loc) · 1.42 KB
/
2021.01.20.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
select name, installed_version, comment
from pg_available_extensions
where name like 'pl%';
DO 'BEGIN END;';
DO
$$
DECLARE
/*
Тестовый комментарий
*/
var1 text;
var2 text := 'World';
BEGIN
-- one line comment
var1 := 'Hello';
RAISE NOTICE '%, %!', var1, var2;
END;
$$;
CREATE FUNCTION fmt_in(IN phone text) RETURNS text
AS
$$
BEGIN
IF phone ~ '^[0-9]*$' AND length(phone) = 10 THEN
RETURN '+7(' || substr(phone, 1, 3) || ')'
|| substr(phone, 4, 3) || '-'
|| substr(phone, 4, 2) || '-'
|| substr(phone, 9);
ELSE
RETURN NULL;
END IF;
END;
$$ LANGUAGE plpgsql IMMUTABLE;
SELECT fmt_in('789');
SELECT fmt_in('9899876541');
CREATE FUNCTION fmt_out(IN phone text, OUT retval text)
AS
$$
BEGIN
retval := fmt_in(phone);
END;
$$ LANGUAGE plpgsql IMMUTABLE;
SELECT fmt_out('1234567897');
CREATE FUNCTION fmt_inout(INOUT phone text)
AS
$$
BEGIN
END;
$$ LANGUAGE plpgsql IMMUTABLE;
SELECT fmt_inout('1234567891');
CREATE FUNCTION reverse_for(line text) RETURNS text
AS
$$
DECLARE
line_length CONSTANT int = length(line);
retval text := '';
BEGIN
FOR i IN 1 .. line_length
LOOP
retval := substr(line, i, 1) || retval;
END LOOP;
RETURN retval;
END;
$$
LANGUAGE plpgsql
IMMUTABLE
STRICT;
SELECT reverse_for('АБЫРВАЛг');