Repository navigation
|
Is it possible to express EXCEPT DISTINCT in Logica? I would like to verify that the results of a query are as expected, and it seems that Standard SQL will allow me to diff tables with EXCEPT DISTINCT and UNION ALL, although there are some limitations. |
Replies: 1 comment 1 reply
|
This can be done with disjunction and negation. A(x) :- x in [1,2,3,4];
B(x) :- x in [2,3,4,5];
Difference(x) :- (A(x), ~B(x)) | (B(x), ~A(x));You can add more info to the result to simplify debugging: A(x) :- x in [1,2,3,4];
B(x) :- x in [2,3,4,5];
Difference(x, reason:) :-
(A(x), ~B(x), reason == "A but not B") |
(B(x), ~A(x), reason == "B but not A");Note that here the difference is taken for a predicate over 1 argument. Taking difference of full rows would require some more work. If the goal is to unit-test the program, it could be more productive to set up a testing framework and test in with a simple text diff. Please let me know if you have further questions. |
This can be done with disjunction and negation.
You can add more info to the result to simplify debugging:
Note that here the difference is taken for a predicate over 1 argument.
It would work the same way if you repeat a few arguments.
Taking difference of full rows would require some more work.
If the goal is to unit-test the program, it could be more productive to set up a testing framework and test in with a simple text diff.
A nic…