This frontend translates a subset of SQL3 query expressions to datalog queries.
You can specify a (possibly recursive) query specification. Currently accepted are expressions of the following form:
[ WITH [RECURSIVE]
Relationname [ ( Columnname [, ... ] ) ] AS ( Query Expression )
[, ... ]
] SELECT [ (Cor-)Relationname .] Columnname [, ... ]
FROM Relationname [ [AS] Correlationname] [, ... ]
[ WHERE [ (Cor-)Relationname .] Columnname = [ (Cor-)Relationname .] Columnname
[ AND [ (Cor-)Relationname .] Columnname = [ (Cor-)Relationname .] Columnname
[ AND ...] ] ;
] [ UNION
SELECT (etc. same as above) ]
Every Relation must be declared using
DATALOG SCHEMA Relationname(Columnname, ...), ... ;
You can express recursion by using a relation declared in the WITH list in the corresponding Sub-Query-Expression. This is the way that was chosen by the ISO/ANSI committee.
The classical List of Materials Query can be expressed in SQL3 in the following way:
DATALOG SCHEMA consists_of(major,minor);
WITH RECURSIVE listofmaterials(major,minor) AS (
SELECT c.major, c.minor FROM consists_of AS c
SELECT c1.major, c2.minor
FROM consists_of AS c1, listofmaterials AS c2
WHERE c1.minor = c2.major
SELECT major, minor FROM listofmaterials;
The specification of a SQL3 query in DLV consists of two separate files, one with extension .db and storing the extensional database (EDB) and another one with extension .sql storing the SQL3 query.
For instance, for the List of Materials example, the query shown above should be stored in a file named materials.sql while the relation consist_of should be stored in a file named materials.db.
The SQL3 front-end is invoked through the option -FS:
DLV -FS [DLV options] materials.db materials.sql