Questions tagged [three-valued-logic]

logic using true, false and a third undetermined value

What is it?

A three-valued logic is a logic in whic every variable or term can have three possible truth value. In practice it will be a value for meaning TRUE, a value for meaning FALSE, and a third value which means that the value is not known (unknown, undetermined).

For example, SQL implements a three-valued logic, interpreting NULL as unknown.

See also

20 questions
13
votes
7 answers

Options for eliminating NULLable columns from a DB model (in order to avoid SQL's three-valued logic)?

Some while ago, I've been reading through the book SQL and Relational Theory by C. J. Date. The author is well-known for criticising SQL's three-valued logic (3VL).1) The author makes some strong points about why 3VL should be avoided in SQL,…
8
votes
5 answers

Example of three valued logic in SQL Server

I understand that SQL uses three valued logic but I am having trouble understanding how to use this in practice, especially why TRUE || NULL = True and FALSE && NULL = False instead of evaluating to null. Here are the three valued truth tables…
John Smith
  • 7,243
  • 6
  • 49
  • 61
7
votes
3 answers

Is SQL unknown identical to NULL?

I'm confused what does UNKNOWN means in SQL in 3 valued logic. Does it mean NULL actually? Is it true that NULL and UNKNOWN can be interchangeable in all boolean contexts?
Michael Tsang
  • 678
  • 5
  • 16
4
votes
1 answer

Spark Scala : Check if string isn't null or empty

First, due to the three value logic, this isn't just the negation of any valid implementation of a null-or-empty check. I want to make a function isNotNullish , which is as close as possible to isNotNull but also filters out empty strings. I'm…
Edward Peters
  • 3,623
  • 2
  • 16
  • 39
3
votes
1 answer

How to apply 3-valued-logic to SQL queries?

I've been doing past paper questions and keep coming up against these questions that deal with 3 valued logic. My notes mention it but don't give examples that relate to those asked in exams. I understand the basis that True = 1, False = 0 &…
3
votes
8 answers

How should I test a field against an SQL variable which can be null?

I've got the following SQL : CREATE TABLE tbFoo( a varchar(50) NULL, ) CREATE NONCLUSTERED INDEX IX_tbFoo_a ON tbFoo ( a ASC ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF,…
Brann
  • 31,689
  • 32
  • 113
  • 162
2
votes
2 answers

NOT IN does not produce same results as NOT EXISTS

These are rather basic statements. I have a list of graphics which are linked to items in another table. I want to check how many of the graphics are not in use and can theoretically be deleted. So first I used the NOT IN clause: SELECT [GraphicNr] …
Dabrush
  • 31
  • 1
2
votes
2 answers

Why is `NOT(NULL=NULL)` false?

(NULL = NULL) is false. Fine. Memorise as "NULL is defined not to be equal to anything". (NULL = NULL) is false. Uhhh ... OK, fair enough . Memorise as "NULL represents an undefined value, so you never know whether it is or isn't equal to…
Brondahl
  • 7,402
  • 5
  • 45
  • 74
2
votes
2 answers

All possible combinations of Three-valued logic values

Is there an algorithm to lead all possible combinations of given amount of three-valued logic values? For example, F(2) should return this list: t t t u t f u t u u u f f t f u f f The function would look like this (in Haskell): data Tril = FALSE |…
Ryoichiro Oka
  • 1,949
  • 2
  • 13
  • 20
2
votes
1 answer

Numeric comparisons with NA values causing bad subsets in R

Can somebody explain to me why logical evaluations that resolve to NA produce bogus rows in vector-comparison-based subsets? For example: employee <- c("Big Shot CEO", "Programmer","Intern","Guy Who Got Fired Last Week") salary <- c( …
C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
1
vote
2 answers

SQL how to store meaningful null values?

My column needs to store the output of a function that returns an integer or null, where null is a meaningful value such as 'unknown', while also having a null value for the column to mean unset/missing. If the value were a three-valued boolean…
Starbuck
  • 29
  • 3
1
vote
1 answer

SQLthree valued logic - do de Morgan's laws apply?

de Morgan's laws apply to 2-valued logic. Does it apply to SQL's 3-valued logic? Experimenting with pen and paper suggests it does but does anyone know of a definitive statement that it really does, given I may have overlooked some corner case.
user3779002
  • 566
  • 4
  • 17
1
vote
1 answer

A three-valued boolean logic with Z3 solver

I have been trying to define a three-valued propositional logic and reason about it using Z3 SMT Solver. To be more precise, I have define a sort Boolean with three values: TRUE, FALSE and NULL with some assertions. (declare-sort Boolean 0) ;I…
HoaNg
  • 25
  • 2
1
vote
4 answers

compare three variables and get the variable with min/max value back (not value)

I have 3 variables with long values timestamp1 timestamp2 timestamp3 and an arraylist timestampList. I want to compare them in an if/else. It could be possible, that the three timestamps have different values, so I want to add the values with the…
NECben067
  • 427
  • 1
  • 4
  • 20
1
vote
3 answers

SQL that check for Duplicates with NULL doesn't not return

I am using 2 separate query to check for duplicates and both query were supposed to give the same answer when executed, however it did not. Below is an example of my database table data: id Name Age Group…
Need Help
  • 39
  • 4
1
2