-
Notifications
You must be signed in to change notification settings - Fork 1
/
prelude.sql
64 lines (55 loc) · 1.74 KB
/
prelude.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
create table if not exists transaction_valid_tstzrange (
transaction_time tstzrange_half_open not null
default tstzrange(current_timestamp, 'infinity', '[)')
,
valid_time tstzrange_half_open not null
default tstzrange(current_timestamp, 'infinity', '[)')
);
create table if not exists transaction_valid_daterange (
transaction_time tstzrange_half_open not null
default tstzrange(current_timestamp, 'infinity', '[)')
,
valid_time daterange_half_open not null
default daterange(current_date, 'infinity', '[)')
);
create type "RoleType" as ENUM ('OrganizationUser', 'OrganizationAdmin', 'SuperAdmin');
create table language_iso639 (
code char(2) primary key -- ISO 639-1
,code3 char(3) not null -- ISO 639-2/T
,CHECK (code=lower(code))
,CHECK (code3=lower(code3))
);
create table language_official_name (
metadata integer not null
,language_code char(2) not null references language_iso639(code)
,name_code char(2) not null references language_iso639(code)
,name varchar not null
,EXCLUDE USING gist (
language_code with =
,name_code with =
,transaction_time with &&
,valid_time with &&
)
) INHERITS (transaction_valid_daterange);
-- TODO: Too lazy to do this more properly
INSERT INTO language_iso639
select * from
(
select 'en' a,'eng' b
union all select 'zh','zho'
union all select 'fi','fin'
union all select 'ru','rus'
) tmp
where tmp.a not in (select code from language_iso639);
create or replace function point_to_json(location geometry(point)) RETURNS json
AS $$
BEGIN
RETURN point_to_json(location::point);
END;
$$ LANGUAGE plpgsql;
create or replace function point_to_json(location point) RETURNS json
AS $$
BEGIN
RETURN ('{"x":'||location[0]||',"y":'||location[1]||'}')::json;
END;
$$ LANGUAGE plpgsql;