1 library(cql/cql): CQL - Constraint Query Language
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • Constraint Query Language A high level interface to SQL databases
        • library(cql/cql): CQL - Constraint Query Language
          • Warnings from CQL
          • CQL: Retrieved nulls have special logic to handle outer joins
          • CQL: Getting Started Quickly
          • Debugging CQL queries
          • Prolog Variables in CQL queries
          • CQL Special Attributes
          • CQL Examples
          • CQL: Hooks

1.5 Prolog Variables in CQL queries

A Prolog variable can be simultaneously a SELECT variable, a JOIN variable and a WHERE variable as A is in the following example:

{[],
 se_lt_x :: [a-A, c-C]
 =*=
 se_lt_y :: [d-A, f-F],
 A == 'A4'}

which generates the following SQL

SELECT
  x_192.a, x_192.c, y_73.d, y_73.f
 FROM
  se_lt_x x_192 INNER JOIN se_lt_y y_73 ON y_73.d=x_192.a
 WHERE   x_192.a = ? and y_73.d = ?

Note how all the variables referenced in the query are retrieved in the SELECT. This is done to make the query Prolog-like. This means the retrieved row should behave like a Prolog fact so that when a query succeeds all the variables become instantiated.

There is one notable exception however: WHERE variables and JOIN variables are not bound in aggregation selections

FIXME: Is this still the case?

sum_test :-
  {[],
   #se_lt_x :: [a-ValueA,
                sum(b)-Summation]
   =*=
   #se_lt_y :: [e-ValueB],

   ValueA == ValueB,   % Explicit join point

   group_by([ValueA])},

  writeln(ValueA-ValueB-Summation).
'ELSTON_M'-_G375971-99450
true ;