function load_triple() basically working

This commit is contained in:
Helmut Merz 2020-02-18 16:16:20 +01:00
parent 6283f0246b
commit ddad67a8f7

View file

@ -33,3 +33,39 @@ begin
return value; return value;
end; end;
$$ language plpgsql; $$ language plpgsql;
create or replace function load_triple(
stname text, stext text, ptext text,
otname text, otext text, event bigint) returns bigint as $$
declare
st smallint;
sv bigint;
pred bigint;
ot smallint;
ov bigint;
trid bigint;
begin
select dt.id into st from datatypes dt where dt.dtname = stname;
select dt.id into ot from datatypes dt where dt.dtname = otname;
sv := get_value(stname, stext);
pred := get_value(stname, ptext);
ov := get_value(otname, otext);
select tr.id into trid from triples tr
where stype = st and svalue = sv and predicate = pred
and otype = ot and ovalue = ov;
if trid is null then
insert into triples (stype, svalue, predicate, otype, ovalue, creation)
values (st, sv, pred, ot, ov, event)
returning triples.id into trid;
end if;
return trid;
end;
$$ language plpgsql;
create or replace function get_event(out evt bigint) as $$
begin
insert into events default values returning id into evt;
end;
$$ language plpgsql;