![]() ![]() To check if a value is not NULL, you use the IS NOT NULL operator: value IS NOT NULL Code language: SQL (Structured Query Language) ( sql ) Here is the output: PostgreSQL IS NOT NULL operator Phone IS NULL Code language: SQL (Structured Query Language) ( sql ) So to get the contact who does not have any phone number stored in the phone column, you use the following statement instead: SELECT id, The expression returns true if the value is NULL or false if it is not. To check whether a value is NULL or not, you use the IS NULL operator instead: value IS NULL Code language: SQL (Structured Query Language) ( sql ) This is because NULL is not equal to any value even itself. ![]() This is because the expression phone = NULL in the WHERE clause always returns false.Įven though there is a NULL in the phone column, the expression NULL = NULL returns false. Phone = NULL Code language: SQL (Structured Query Language) ( sql ) ![]() To find the contact who does not have a phone number you may come up with the following statement: SELECT id, The following statement inserts two contacts, one has a phone number and the other does not: INSERT INTO contacts(first_name, last_name, email, phone) In this case, you can use the following statement: CREATE TABLE contacts( If you get an error while executing the CREATE TABLE statement, your PostgreSQL version may not support the identity column syntax. For now, you just need to execute the above statement to create the contacts table. Note that you will learn how to create a new table in the subsequent tutorial. ) Code language: SQL (Structured Query Language) ( sql ) To deal with this, you define the phone column as a nullable column and insert NULL into the phone column when you save the contact information. At the time of recording the contact, you may not know the contact’s phone number. In addition, NULL is not equal to NULL so the following expression returns NULL: NULL = NULL Code language: SQL (Structured Query Language) ( sql )Īssuming that you have a contacts table that stores the first name, last name, email, and phone number of contacts. The comparison of NULL with a value will always result in NULL, which means an unknown result. NULL is not a value, therefore, you cannot compare it with any other values like numbers or strings. In the database world, NULL means missing information or not applicable. Introduction to NULL and IS NULL operator Summary: in this tutorial, you will learn how to use the PostgreSQL IS NULL operator to check if a value is NULL or not. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |