0

I understand that relational calculus is based on first order logic and as such has no concept of null values, however a not null constraint can be expressed in a query in relational algebra using an anti-join. Is there an equivalent mechanism to express such a query using only relational calculus?

For example, could a basic SQL query in the form: SELECT * from x WHERE y IS NOT NULL be expressed using relational calculus?

nvogel
  • 24,981
  • 1
  • 44
  • 82
mdmjsh
  • 915
  • 9
  • 20
  • 1
    `WHERE y=y` would suffice – wildplasser Jan 05 '19 at 18:34
  • Nice suggestion - very elegant. Harnessing the power of NULL != NULL – mdmjsh Jan 05 '19 at 19:07
  • 1
    A relational algebra or calculus has a null if and only if it is defined to have it & its operators treat any null the way they are defined to. In SQL null is a value that SQL operators treat specially. Normally/historically when one talks about a relational algebra or calculus it is understood that there is no null. But particular ones have it--typically ones invented for textbook SQL apologetics. Your question is meaningless unless you define your "algebra" & "calculus". (And then the answer becomes straightforward.) – philipxy Jan 06 '19 at 03:56
  • 1
    [Expressing “is null” in Relational algebra](https://stackoverflow.com/a/43430524/3404097) – philipxy Jan 06 '19 at 04:11
  • 1
    Constraints & queries are different things. Also the meaning of each of those terms depends on context. But it seems like when you say "not null constraint" you mean something like "predicate expression with one free (logic) variable that is true if & only if its free variable is assigned a value other than null". But you're not clear. PS You tagged this with tuple relational calculus but you just say "relational calculus" in your question. Do you understand that there are two kinds of relational calculus, tuple & domain? Do you really care about one specifically? – philipxy Jan 07 '19 at 06:47

1 Answers1

1

E.F.Codd proposed introducing nulls to the relational model but he never seemed to deal with the consequences. In his book, "Relational Model for Database Management", he proposed using two different kinds of null and a four-value logic. He suggested such a system would need a tautology detection algorithm to make sure the right result (or at least a useful, comprehensible result) would be returned for some queries. It seems to me that such a scheme must be impractical and doomed to fail, although I have no proof. To me it seems unlikely that users would be able to understand tautology detection properly.

Under Codd's scheme, short circuit operations like x=x would presumably evaluate to true, even in the presence of nulls. The authors of SQL did not follow Codd's scheme of course, and there lies the difficulty. There is no single consistent set of rules for the treatment of nulls either in theory or in working software, so unless you explain such a system and its rules your question is unanswerable.

nvogel
  • 24,981
  • 1
  • 44
  • 82