provide function and view for displaying triples; + examples directory

This commit is contained in:
Helmut Merz 2020-02-18 09:06:10 +01:00
parent e5b06d5ffc
commit fca4f3643c
6 changed files with 73 additions and 3 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/data/

View file

@ -0,0 +1,35 @@
rectype,ctype,regiokey,ckey,name,area,inhabitants,zipcode,long,lat
40,42,08111,08111,"Stuttgart, Stadtkreis",,,,,
50,50,081110000,08111,"Stuttgart, Landeshauptstadt",,,,,
60,62,081110000000,08111000,"Stuttgart, Landeshauptstadt",207.33,634830,70173,9.177734,48.775817
40,44,08115,08115,Böblingen,,,,,
50,50,081150003,08115,"Böblingen, Stadt",,,,,
60,67,081150003003,08115003,"Böblingen, Stadt",39.04,50155,71032,9.009663,48.685296
50,50,081150052,08115,Weissach,,,,,
60,64,081150052052,08115052,Weissach,22.19,7519,71287,8.927545,48.846812
50,56,081155001,08115,GVV Aidlingen/Grafenau,,,,,
60,64,081155001001,08115001,Aidlingen,26.56,9024,71134,8.896991,48.677969
60,64,081155001054,08115054,Grafenau,13.04,6747,71120,8.91395,48.711098
50,56,081155002,08115,GVV Gärtringen/Ehningen,,,,,
60,64,081155002013,08115013,Ehningen,17.81,9193,71139,8.940525,48.65926
60,64,081155002015,08115015,Gärtringen,20.21,12417,71116,8.901692,48.641924
50,54,081155003,08115,VVG der Stadt Herrenberg,,,,,
60,64,081155003010,08115010,Deckenpfronn,11.41,3329,75392,8.822512,48.65171
60,67,081155003021,08115021,"Herrenberg, Stadt",65.7,31545,71083,8.867369,48.595705
60,64,081155003037,08115037,Nufringen,10.04,5872,71154,8.888193,48.622489
40,44,08116,08116,Esslingen,,,,,
50,50,081160015,08116,Denkendorf,,,,,
60,64,081160015015,08116015,Denkendorf,13.05,11240,73770,9.31755,48.694154
50,50,081160019,08116,"Esslingen am Neckar, Stadt",,,,,
60,67,081160019019,08116019,"Esslingen am Neckar, Stadt",46.43,93542,73728,9.309565,48.741347
50,54,081165001,08116,VVG der Stadt Kirchheim unter Teck,,,,,
60,64,081165001016,08116016,Dettingen unter Teck,15.13,6142,73265,9.45268,48.61725
60,67,081165001033,08116033,"Kirchheim unter Teck, Stadt",40.47,40523,73230,9.453784,48.646093
60,64,081165001048,08116048,Notzingen,7.7,3687,73274,9.462005,48.671109
50,56,081165003,08116,GVV Neckartenzlingen,,,,,
60,64,081165003005,08116005,Altdorf,3.24,1700,72655,9.271505,48.594688
60,64,081165003006,08116006,Altenriet,3.35,1921,72657,9.221764,48.591482
60,64,081165003008,08116008,Bempflingen,6.27,3485,72658,9.26546,48.573217
60,64,081165003041,08116041,Neckartailfingen,8.23,3846,72666,9.262633,48.61255
60,64,081165003042,08116042,Neckartenzlingen,9.03,6498,72654,9.233903,48.590722
60,64,081165003063,08116063,Schlaitdorf,7.31,1931,72667,9.222445,48.604296
1 rectype ctype regiokey ckey name area inhabitants zipcode long lat
2 40 42 08111 08111 Stuttgart, Stadtkreis
3 50 50 081110000 08111 Stuttgart, Landeshauptstadt
4 60 62 081110000000 08111000 Stuttgart, Landeshauptstadt 207.33 634830 70173 9.177734 48.775817
5 40 44 08115 08115 Böblingen
6 50 50 081150003 08115 Böblingen, Stadt
7 60 67 081150003003 08115003 Böblingen, Stadt 39.04 50155 71032 9.009663 48.685296
8 50 50 081150052 08115 Weissach
9 60 64 081150052052 08115052 Weissach 22.19 7519 71287 8.927545 48.846812
10 50 56 081155001 08115 GVV Aidlingen/Grafenau
11 60 64 081155001001 08115001 Aidlingen 26.56 9024 71134 8.896991 48.677969
12 60 64 081155001054 08115054 Grafenau 13.04 6747 71120 8.91395 48.711098
13 50 56 081155002 08115 GVV Gärtringen/Ehningen
14 60 64 081155002013 08115013 Ehningen 17.81 9193 71139 8.940525 48.65926
15 60 64 081155002015 08115015 Gärtringen 20.21 12417 71116 8.901692 48.641924
16 50 54 081155003 08115 VVG der Stadt Herrenberg
17 60 64 081155003010 08115010 Deckenpfronn 11.41 3329 75392 8.822512 48.65171
18 60 67 081155003021 08115021 Herrenberg, Stadt 65.7 31545 71083 8.867369 48.595705
19 60 64 081155003037 08115037 Nufringen 10.04 5872 71154 8.888193 48.622489
20 40 44 08116 08116 Esslingen
21 50 50 081160015 08116 Denkendorf
22 60 64 081160015015 08116015 Denkendorf 13.05 11240 73770 9.31755 48.694154
23 50 50 081160019 08116 Esslingen am Neckar, Stadt
24 60 67 081160019019 08116019 Esslingen am Neckar, Stadt 46.43 93542 73728 9.309565 48.741347
25 50 54 081165001 08116 VVG der Stadt Kirchheim unter Teck
26 60 64 081165001016 08116016 Dettingen unter Teck 15.13 6142 73265 9.45268 48.61725
27 60 67 081165001033 08116033 Kirchheim unter Teck, Stadt 40.47 40523 73230 9.453784 48.646093
28 60 64 081165001048 08116048 Notzingen 7.7 3687 73274 9.462005 48.671109
29 50 56 081165003 08116 GVV Neckartenzlingen
30 60 64 081165003005 08116005 Altdorf 3.24 1700 72655 9.271505 48.594688
31 60 64 081165003006 08116006 Altenriet 3.35 1921 72657 9.221764 48.591482
32 60 64 081165003008 08116008 Bempflingen 6.27 3485 72658 9.26546 48.573217
33 60 64 081165003041 08116041 Neckartailfingen 8.23 3846 72666 9.262633 48.61255
34 60 64 081165003042 08116042 Neckartenzlingen 9.03 6498 72654 9.233903 48.590722
35 60 64 081165003063 08116063 Schlaitdorf 7.31 1931 72667 9.222445 48.604296

16
pgsql/fshow.sql Normal file
View file

@ -0,0 +1,16 @@
create or replace function show(type smallint, id bigint) returns text as $$
declare tname text := (select dtname from datatypes as dt where dt.id = type);
begin
case tname
when 'node' then
return (
select ns.prefix || ':' || n.name
from nodes n
join namespaces ns on ns.id = n.namespace
where n.id = show.id
);
else return tname;
end case;
end;
$$ language plpgsql;

View file

@ -75,15 +75,17 @@ INSERT INTO nodes (namespace, name) VALUES
-- type -> Property; Property, Class -> Class -- type -> Property; Property, Class -> Class
INSERT INTO triples (stype, svalue, predicate, otype, ovalue, creation) VALUES INSERT INTO triples (stype, svalue, predicate, otype, ovalue, creation) VALUES
(2, 1, 2, 2, 2, 1), (2, 1, 1, 2, 2, 1),
(2, 2, 2, 2, 3, 1), (2, 2, 1, 2, 3, 1),
(2, 3, 2, 2, 3, 1); (2, 3, 1, 2, 3, 1);
-- indexes -- indexes
CREATE INDEX idx_iri ON namespaces USING btree (iri); CREATE INDEX idx_iri ON namespaces USING btree (iri);
CREATE INDEX idx_prefix ON namespaces USING btree (prefix); CREATE INDEX idx_prefix ON namespaces USING btree (prefix);
CREATE INDEX idx_dtname ON datatypes USING btree (dtname);
CREATE INDEX idx_node_name ON nodes USING btree (namespace, name); CREATE INDEX idx_node_name ON nodes USING btree (namespace, name);
CREATE INDEX fki_stype ON triples USING btree (stype); CREATE INDEX fki_stype ON triples USING btree (stype);

4
pgsql/qtriples.sql Normal file
View file

@ -0,0 +1,4 @@
select id, stext, ptext, otext, ts
from vtriples

12
pgsql/vtriples.sql Normal file
View file

@ -0,0 +1,12 @@
create or replace view vtriples as
select triples.id,
stype, svalue, show(stype, svalue) as stext,
predicate, show(dt.id, predicate) as ptext,
otype, ovalue, show(otype, ovalue) as otext,
events.tstamp as ts
from triples, datatypes dt, events
where dtname = 'node'
and events.id = creation
and deletion is null
;