Skip to content

Support for EXISTS constraint #359

Answered by EvgSkv
rvalek asked this question in Q&A
Jul 11, 2024 · 4 comments · 9 replies
Discussion options

You must be logged in to vote

@rvalek I looked at it. There is some type casting that was added for robustness, which prevents exists working as-is. But we can figure that part out.

For now I created exists branch, where I disabled the type casting of aggregates.

There you can do:

Exists(e) :- Constraint(SqlExpr("exists ({e})", {e:}));
# Making it sound more humane :-D
ForReal(x) = Aggr(x);

@Ground(T);
T(1);
T(3);
T(7);
T(20);

@Ground(D);
D(x) :- x in Range(10);

Q(x) :- D(x), Exists(ForReal{x :- T(x)});

Which produces (as expected):

+------+
| col0 |
+------+
| 1    |
| 3    |
| 7    |
+------+

By default SQL that you get looks like this:

SELECT
  D.col0 AS col0
FROM
  logica_home.D AS D
WHERE
  exists ((SELECT
 …

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
6 replies
@EvgSkv
Comment options

Answer selected by rvalek
@rvalek
Comment options

@rvalek
Comment options

@rvalek
Comment options

@EvgSkv
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@mikko-ahonen
Comment options

@rvalek
Comment options

@mikko-ahonen
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants