use separate init.sql that only calls other scripts
This commit is contained in:
parent
8956bdb35e
commit
6879a9254c
6 changed files with 58 additions and 37 deletions
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
-- create load functions
|
||||
|
||||
create or replace function get_value(tname text, vtext text) returns bigint as $$
|
||||
begin
|
||||
case tname
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
-- create show functions
|
||||
|
||||
create or replace function show_value(type smallint, id bigint) returns text as $$
|
||||
declare tname text := (select dtname from datatypes as dt where dt.id = type);
|
||||
begin
|
||||
|
|
@ -10,13 +12,18 @@ create or replace function show_value(tname text, id bigint) returns text as $$
|
|||
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_value.id
|
||||
);
|
||||
else return text(show_value.id);
|
||||
return show_node(id);
|
||||
else
|
||||
return text(show_value.id);
|
||||
end case;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
|
||||
create or replace function show_node(nid bigint) returns text as $$
|
||||
select ns.prefix || ':' || n.name from nodes n
|
||||
join namespaces ns on ns.id = n.namespace
|
||||
where n.id = nid;
|
||||
$$ language sql;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +1,11 @@
|
|||
|
||||
-- create tables and views
|
||||
\i tcreate.sql
|
||||
\i vtriples.sql
|
||||
|
||||
-- create functions
|
||||
\i fload.sql
|
||||
\i fshow.sql
|
||||
|
||||
select new_event() as event
|
||||
\gset
|
||||
|
||||
-- load data
|
||||
|
||||
select load_namespace('http://cyberconcepts.org/cco-common#', 'cco');
|
||||
select load_namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf');
|
||||
select load_namespace('http://www.w3.org/2000/01/rdf-schema#', 'rdfs');
|
||||
|
||||
select load_datatype('namespace', 'namespaces');
|
||||
select load_datatype('node', 'nodes');
|
||||
select load_datatype('datatype', 'datatypes');
|
||||
select load_datatype('event', 'events');
|
||||
select load_datatype('triple', 'triples');
|
||||
select load_datatype('text', 'texts');
|
||||
select load_datatype('int');
|
||||
select load_datatype('decimal');
|
||||
select load_datatype('timestamp');
|
||||
|
||||
-- basic triples: type assignments for
|
||||
-- type -> Property; Property, Class -> Class
|
||||
|
||||
select load_triple('node', 'rdf:type', 'rdf:type', 'node', 'rdf:Property', :event);
|
||||
select load_triple('node', 'rdf:Property', 'rdf:type', 'node', 'rdfs:Class', :event);
|
||||
select load_triple('node', 'rdfs:Class', 'rdf:type', 'node', 'rdfs:Class', :event);
|
||||
\i lbase.sql
|
||||
|
|
|
|||
28
pgsql/lbase.sql
Normal file
28
pgsql/lbase.sql
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
-- load base data
|
||||
|
||||
select new_event() as event
|
||||
\gset
|
||||
|
||||
-- load data
|
||||
|
||||
select load_namespace('http://cyberconcepts.org/cco-common#', 'cco');
|
||||
select load_namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf');
|
||||
select load_namespace('http://www.w3.org/2000/01/rdf-schema#', 'rdfs');
|
||||
|
||||
select load_datatype('namespace', 'namespaces');
|
||||
select load_datatype('node', 'nodes');
|
||||
select load_datatype('datatype', 'datatypes');
|
||||
select load_datatype('event', 'events');
|
||||
select load_datatype('triple', 'triples');
|
||||
select load_datatype('text', 'texts');
|
||||
select load_datatype('int');
|
||||
select load_datatype('decimal');
|
||||
select load_datatype('timestamp');
|
||||
|
||||
-- basic triples: type assignments for
|
||||
-- type -> Property; Property, Class -> Class
|
||||
|
||||
select load_triple('node', 'rdf:type', 'rdf:type', 'node', 'rdf:Property', :event);
|
||||
select load_triple('node', 'rdf:Property', 'rdf:type', 'node', 'rdfs:Class', :event);
|
||||
select load_triple('node', 'rdfs:Class', 'rdf:type', 'node', 'rdfs:Class', :event);
|
||||
|
|
@ -1,21 +1,23 @@
|
|||
-- tables
|
||||
|
||||
-- create tables
|
||||
|
||||
CREATE TABLE namespaces (
|
||||
id serial NOT NULL primary key,
|
||||
iri text NOT NULL,
|
||||
prefix text
|
||||
iri text NOT NULL unique,
|
||||
prefix text unique
|
||||
);
|
||||
|
||||
CREATE TABLE datatypes (
|
||||
id smallserial NOT NULL primary key,
|
||||
dtname text NOT NULL,
|
||||
dtname text NOT NULL unique,
|
||||
tablename text
|
||||
);
|
||||
|
||||
CREATE TABLE nodes (
|
||||
id bigserial NOT NULL primary key,
|
||||
namespace bigint REFERENCES namespaces,
|
||||
name text
|
||||
name text,
|
||||
unique (namespace, name)
|
||||
);
|
||||
|
||||
CREATE TABLE events (
|
||||
|
|
@ -37,7 +39,7 @@ CREATE TABLE triples (
|
|||
CREATE TABLE texts (
|
||||
id bigserial NOT NULL primary key,
|
||||
language bigint REFERENCES nodes,
|
||||
text text NOT NULL
|
||||
text text NOT NULL unique
|
||||
);
|
||||
|
||||
-- set table owner
|
||||
|
|
@ -66,3 +68,4 @@ CREATE INDEX idx_po ON triples USING btree (predicate, otype, ovalue);
|
|||
CREATE INDEX idx_os ON triples USING btree (otype, ovalue, stype, svalue);
|
||||
|
||||
CREATE INDEX fki_language ON texts USING btree (language);
|
||||
CREATE INDEX idx_texts ON texts USING btree (text);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
-- create triples views
|
||||
|
||||
create or replace view vtriples as
|
||||
select triples.id,
|
||||
stype, svalue, show_value(stype, svalue) as stext,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue