Search code examples
sqllogicbloxlogiql

How to query logicblox


I have an entity predicate eg. "Person" with related functional predicates storing attributes about the entity.

Eg.

Person(x), Person:id(x:s) -> string(s).

Person:dateOfBirth[a] = b -> Person(a), datetime(b).
Person:height[a] = b -> Person(a), decimal(b).
Person:eyeColor[a] = b -> Person(a), string(b).
Person:occupation[a] = b -> Person(a), string(b).

What I would like to do is in the terminal, do the equivalent of the SQL query:

SELECT id, dateOfBirth, eyeColor FROM Person

I am aware of the print command to get the details of a single functional predicate, but I would like to get a combination of them.

lb print /workspace 'Person:dateOfBirth'

Solution

  • You can use the "lb query" command to execute arbitrary logiql queries against your database. Effectively you create a temporary, anonymous, predicate with the results you want to see, and then a rule for populating that predicate using the logiql language. So in your case it would be something like:

    lb query <workspace> '_(id, dob, eye) <- 
      Person(p),
      Person:id(p:id),
      Person:dateOfBirth[p] = dob,
      Person:eyeColor[p] = eye.'