function load_triple() basically working
This commit is contained in:
parent
6283f0246b
commit
ddad67a8f7
1 changed files with 36 additions and 0 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue