Suppose I have the following two tables
(clsql:def-view-class class-a ()
((field-one :type integer
:db-kind :key
:db-constraints :auto-increment)
(field-two :type string
:initarg :two
:db-constraints :not-null)))
(clsql:def-view-class class-b ()
((b-one :type integer
:initarg :b-one
:db-kind :key)))
(clsql:create-view-from-class 'class-a)
(clsql:create-view-from-class 'class-b)
Now I want entries of class-a that do not have a corresponding entry in class-b. ("Corresponding" meaning that class-a.field-one maps to class-b.b-one.) Suppose that, class-a has the following two entries:
(clsql:update-records-from-instance (make-instance 'class-a :two "hello"))
(clsql:update-records-from-instance (make-instance 'class-a :two "world"))
So, the query to issue would be:
(clsql:select 'class-a :from [class-a] ; class-b is added "magically"
:where [not [in [class-a field-one]
[select [class-b b-one] :from [class-b]
:where [= [class-a field-one]
[class-b b-one]]]]])
However, this adds class-b as well. (With a purposeful error, I get the query executed as:)
SELECT CLASS_A.FIELD_ONE,CLASS_A.FIELD_TWO FROM CLASS_A,CLASS_B
WHERE (NOT ((CLASS_A.FIELD_ONE
IN (SELECT CLASS_B.B_ONE FROM CLASS_B
WHERE (CLASS_A.FIELD_ONE = CLASS_B.B_ONE)))))
On the other hand,
(clsql:select [*] :from [class-a] ; see the [*]
:where [not [in [class-a field-one]
[select [class-b b-one] :from [class-b]
:where [= [class-a field-one]
[class-b b-one]]]]])
is translated to the expected:
SELECT * FROM CLASS_A
WHERE (NOT ((CLASS_A.FIELD_ONE
IN (SELECT CLASS_B.B_ONE FROM CLASS_B
WHERE (CLASS_A.FIELD_ONE = CLASS_B.B_ONE)))))
Is this a bug or is there some reasoning behind this translation?