This is the fastest way to learn the core pg_liquid model.
Graph facts are ordinary Liquid assertions:
select *
from liquid.query($$
Edge("alice", "knows", "bob").
Edge("bob", "knows", "carol").
Edge(subject, predicate, object)?
$$) as t(subject text, predicate text, object text)
order by 1, 2, 3;
Each Edge(subject, predicate, object) assertion inserts one graph fact.
select *
from liquid.query($$
Edge("alice", "knows", "bob").
Edge("alice", "likes", "datalog").
Edge("alice", predicate, object)?
$$) as t(predicate text, object text)
order by 1;
Rules are query-local. They do not persist in the database.
select reachable
from liquid.query($$
Edge("alice", "knows", "bob").
Edge("bob", "knows", "carol").
Edge("carol", "knows", "dana").
Reach(x, y) :- Edge(x, "knows", y).
Reach(x, z) :- Reach(x, y), Reach(y, z).
Reach("alice", reachable)?
$$) as t(reachable text)
order by 1;
Variables are bare identifiers. _ is anonymous.
select object
from liquid.query($$
Edge("alice", "owns", "doc:1").
Edge("alice", "owns", "doc:2").
Edge("alice", "owns", object)?
$$) as t(object text)
order by 1;
? query returns rows