Skip to content

NOT IN table #216

Answered by EvgSkv
rvalek asked this question in Q&A
Jul 13, 2022 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

Doing it via negation is the canonical way of expressing this logic.
But that's right, unfortunately, not all queries compile on Trino just yet.
For now we can hack it as follows:

NotInTable2(id) :-
  Constraint(SqlExpr("{x} NOT IN (SELECT id FROM table2)",
                     {x: id}));

T(id:, name:) :-
  table1(id:, name:),
  NotInTable2(id);

SQL seems to compile as needed:

$ logica not_in.l print T
SELECT
  table1.id AS id,
  table1.name AS name
FROM
  table1
WHERE
  table1.id NOT IN (SELECT id FROM table2);

If it's a rare situation in your program it may be OK. Of course in the future we do want to make the negation compile properly.

Please let me know if you have further questions.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@rvalek
Comment options

@rvalek
Comment options

@rvalek
Comment options

@EvgSkv
Comment options

@rvalek
Comment options

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