Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL "unknown"

Tags:

mysql

I just discovered you can write something like

SELECT NULL IS UNKNOWN

Which returns 1.

Are there any other places you can use UNKNOWN? It doesn't appear to be a keyword (can't do SELECT UNKNOWN). NULL IS NULL is also true, so what purpose does UNKNOWN have?

like image 936
mpen Avatar asked Feb 27 '13 23:02

mpen


People also ask

Why do I get an unknown database error when connecting to MySQL?

When connecting to MySQL, I get an "Unknown Database" error. You connect to the wrong cluster. You connect to a database that doesn’t exist in your specified cluster. Verify that you are using the correct hostname to connect.

How to fix MySQL unknown column in field list error?

Finally, the error can also be caused by invisible characters lurking in your script that can’t be seen when you copy and paste it from other sources. The only way to remove invisible characters is by rewriting the statements manually. The tutorial above has listed the most common cause for MySQL unknown column in field list error.

How do I check if a MySQL database has been created?

This may be checked by looking in /var/lib/mysql for a mysql subfolder (i.e. /var/lib/mysql/mysql ). If the path does NOT contain a mysql subfolder, it needs to be created by completing the following steps: Now that the above steps have been run, check and make sure that the database was created:

How do I find the default MySQL database?

Depending on how MySQL was installed, it is possible that the default MySQL database was NOT created. This may be checked by looking in /var/lib/mysql for a mysql subfolder (i.e. /var/lib/mysql/mysql ).


2 Answers

UNKNOWN is just an alias for BOOLEAN NULL... the same way that TRUE is just an alias for 1 and FALSE is just an alias for 0, since in MySql BOOLEAN itself is just an alias for TINYINT(1)

Why is it even there? Because it's part of the SQL-92 standard:

<truth value> ::=
                TRUE
              | FALSE
              | UNKNOWN

Why can you SELECT NULL, SELECT TRUE, SELECT FALSE, but not SELECT UNKNOWN? Probably just a bug, since UNKNOWN itself wasn't supported until newer versions of MySql.

like image 130
Michael Fredrickson Avatar answered Sep 19 '22 04:09

Michael Fredrickson


Seems to me, in MySQL, UNKNOWN is an alias for NULL, used in a Boolean sense.

I could find this reference:

In SQL, all logical operators evaluate to TRUE, FALSE, or NULL (UNKNOWN).

MySQL docs - 12.3.3. Logical Operators

Some more information on general SQL NULL and UNKNOWN:

When restricted by a NOT NULL constraint, the SQL BOOLEAN works like the Boolean type from other languages. Unrestricted however, the BOOLEAN datatype, despite its name, can hold the truth values TRUE, FALSE, and UNKNOWN, all of which are defined as boolean literals according to the standard. The standard also asserts that NULL and UNKNOWN "may be used interchangeably to mean exactly the same thing".

NULL on Wikipedia

like image 44
kapa Avatar answered Sep 21 '22 04:09

kapa