Questions tagged [null]

Null means *nothing* or *unknown*, depending on context. Please use the "sql-null" tag for SQL specific questions.

"Null" has different meanings depending on context.

Set theory

Null is another name for the empty set, denoted by the symbol ∅. For this reason, some programming languages use null or nil for the empty list or empty tuple. Lisp uses nil to mean the empty list and the boolean value false.

Pointers and References

Null (or sometimes nil or None), in programming languages that support it, is the value of an uninitialized variable, a pointer that doesn't point to a meaningful memory address, or an object that fails to respond to any message.

Nullable references were invented by C.A.R. Hoare in 1965 as part of the Algol W language. Hoare later described his invention as a "billion-dollar mistake".

For more information, see Null pointer.

Agreeing with Hoare's sentiment, many languages don't have a special null value, choosing to use optional types instead.

Relational Databases

NULL as a special marker in SQL or a relational database stands in place of a value that is missing, or in a join means "no corresponding row." The operators IS NULL and IS NOT NULL are required for comparisons to a literal null: other comparisons between NULL and any value evaluate to "unknown."

For more information, see Null (SQL).

ASCII

Null or NUL is the name given to the character with ASCII code zero (0) - i.e. hex 00. In some languages, notably C, NUL is used to mark the end of a character string.

For more information, see Null character.

16208 questions
80
votes
11 answers

How to select rows where column value IS NOT NULL using CodeIgniter's ActiveRecord?

I'm using CodeIgniter's Active Record class to query the MySQL database. I need to select the rows in a table where a field is not set to NULL: $this->db->where('archived !=', 'NULL'); $q = $this->db->get('projects'); That only returns this…
rebellion
  • 6,628
  • 11
  • 48
  • 79
80
votes
6 answers

Undefined or null for AngularJS

When I write watch handling functions I check newVal param on undefined and null. Why does AngularJS have such a behavior, but doesn't have particular utility method? So there is angular.isUndefined but not angular.isUndefinedOrNull. It isn't hard…
slo2ols
  • 1,009
  • 1
  • 8
  • 16
80
votes
7 answers

HashMaps and Null values?

How do you pass in null values into a HashMap? The following code snippet works with options filled in: HashMap options = new HashMap(); options.put("name", "value"); Person person = sample.searchPerson(options); …
Neutron_boy
  • 919
  • 1
  • 6
  • 7
80
votes
5 answers

NULL value in multi-column primary key

I've got a table with several columns making up the primary key. The nature of the data stored allows some of these fields to have NULL values. I have designed my table as such: CREATE TABLE `test` ( `Field1` SMALLINT(5) UNSIGNED NOT NULL, …
simbabque
  • 53,749
  • 8
  • 73
  • 136
79
votes
6 answers

Null safe Collection as Stream in Java 8

I am looking for method that can make stream of collection, but is null safe. If collection is null, empty stream is returned. Like this: Utils.nullSafeStream(collection).filter(...); I have created my own method: public static Stream
Gondy
  • 4,925
  • 4
  • 40
  • 46
78
votes
4 answers

MySQL: get MAX or GREATEST of several columns, but with NULL fields

I'm trying to select the max date in three different fields in each record (MySQL) So, in each row, I have date1, date2 and date3: date1 is always filled, date2 and date3 can be NULL or empty The GREATEST statement is simple and concise but has no…
Ivan
  • 2,463
  • 6
  • 39
  • 51
78
votes
6 answers

Check if KeyValuePair exists with LINQ's FirstOrDefault

I have a dictionary of type Dictionary I want to return the first instance where a condition is met using var available = m_AvailableDict.FirstOrDefault(p => p.Value == 0) However, how do I check if I'm actually getting back a…
Steve
  • 11,763
  • 15
  • 70
  • 103
78
votes
3 answers

Handling null values in protobuffers

I am working on something which fetches data from database and constructs protobuff message. Given the possibility that null values can be fetched from the database for certain fields , I will get Null-pointer exception while trying to construct the…
Aarish Ramesh
  • 6,745
  • 15
  • 60
  • 105
78
votes
6 answers

Allow null in unique column

I've created the following table: CREATE TABLE MMCompany ( CompanyUniqueID BIGSERIAL PRIMARY KEY NOT NULL, Name VARCHAR (150) NOT NULL, PhoneNumber VARCHAR(20) NOT NULL UNIQUE, Email VARCHAR(75) UNIQUE, CompanyLogo BYTEA ); The…
liv a
  • 3,232
  • 6
  • 35
  • 76
77
votes
2 answers

Doctrine 2 OneToMany Cascade SET NULL

The error Cannot delete or update a parent row: a foreign key constraint fails. The classes class Teacher { /** *@ORM\OneToMany(targetEntity="publication", mappedBy="teacher") */ protected $publications; } class Publication { …
Nicolas Lino
  • 771
  • 1
  • 5
  • 4
77
votes
6 answers

Difference between nil, NIL, and null in Objective-C

I want to know the difference between nil, NIL, and null. I've googled around and found this: nil -> null pointer to Objective-C object NIL -> null pointer to Objective-C class null -> null pointer to primitive type or absence of data But I'm not…
shweta
  • 1,120
  • 1
  • 11
  • 25
77
votes
2 answers

Null check in VB

All I want to do is check if an object is null, but no matter what I do, if it compiles, it throws a NullReferenceException just trying to check! Here's what I've done: If ((Not (comp.Container Is Nothing)) And (Not (comp.Container.Components Is…
Ky -
  • 30,724
  • 51
  • 192
  • 308
77
votes
3 answers

PostgreSQL: Create an index to quickly distinguish NULL from non-NULL values

Consider a SQL query with the following WHERE predicate: ... WHERE name IS NOT NULL ... Where name is a textual field in PostgreSQL. No other query checks any textual property of this value, just whether it is NULL or not. Therefore, a full btree…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
77
votes
12 answers

Is it a bad idea if equals(null) throws NullPointerException instead?

The contract of equals with regards to null, is as follows: For any non-null reference value x, x.equals(null) should return false. This is rather peculiar, because if o1 != null and o2 == null, then we have: o1.equals(o2) // returns…
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623
77
votes
2 answers

how do you insert null values into sql server

In sql server enterprise manager, how do you write an insert statement and pass in null values?
leora
  • 188,729
  • 360
  • 878
  • 1,366