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
330
votes
4 answers

NULL vs nullptr (Why was it replaced?)

I know that in C++ 0x or NULL was replaced by nullptr in pointer-based applications. I'm just curious of the exact reason why they made this replacement? In what scenario is using nullptr over NULL beneficial when dealing with pointers?
Riptyde4
  • 5,134
  • 8
  • 30
  • 57
329
votes
13 answers

Checking for a null int value from a Java ResultSet

In Java I'm trying to test for a null value, from a ResultSet, where the column is being cast to a primitive int type. int iVal; ResultSet rs = magicallyAppearingStmt.executeQuery(query); if (rs.next()) { if (rs.getObject("ID_PARENT") != null &&…
ian_scho
  • 5,906
  • 9
  • 35
  • 51
327
votes
6 answers

How to select rows with one or more nulls from a pandas DataFrame without listing columns explicitly?

I have a dataframe with ~300K rows and ~40 columns. I want to find out if any rows contain null values - and put these 'null'-rows into a separate dataframe so that I could explore them easily. I can create a mask explicitly: mask = False for col in…
Lev Selector
  • 3,681
  • 3
  • 17
  • 8
325
votes
6 answers

Why use Optional.of over Optional.ofNullable?

When using the Java 8 Optional class, there are two ways in which a value can be wrapped in an optional. String foobar = ; Optional.of(foobar); // May throw NullPointerException Optional.ofNullable(foobar); // Safe from…
whirlwin
  • 16,044
  • 17
  • 67
  • 98
320
votes
9 answers

MySQL: selecting rows where a column is null

I'm having a problem where when I try to select the rows that have a NULL for a certain column, it returns an empty set. However, when I look at the table in phpMyAdmin, it says null for most of the rows. My query looks something like this: SELECT…
The.Anti.9
  • 43,474
  • 48
  • 123
  • 161
320
votes
16 answers

DateTime "null" / uninitialized value?

How do you deal with a DateTime that should be able to contain an uninitialized value (equivalent to null)? I have a class which might have a DateTime property value set or not. I was thinking of initializing the property holder to…
Mats
  • 14,902
  • 33
  • 78
  • 110
315
votes
12 answers

NULL values inside NOT IN clause

This issue came up when I got different records counts for what I thought were identical queries one using a not in where constraint and the other a left join. The table in the not in constraint had one null value (bad data) which caused that query…
Jamie Ide
  • 48,427
  • 16
  • 81
  • 117
312
votes
21 answers

Checking if an object is null in C#

I would like to prevent further processing on an object if it is null. In the following code I check if the object is null by either: if (!data.Equals(null)) and if (data != null) However, I receive a NullReferenceException at dataList.Add(data).…
developer
  • 7,252
  • 14
  • 49
  • 57
308
votes
4 answers

What is the PostgreSQL equivalent for ISNULL()

In MS SQL-Server, I can do: SELECT ISNULL(Field,'Empty') from Table But in PostgreSQL I get a syntax error. How do I emulate the ISNULL() functionality ?
Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168
307
votes
11 answers

Best way to check for "empty or null value"

What is best way to check if value is null or empty string in Postgres sql statements? Value can be long expression so it is preferable that it is written only once in check. Currently I'm using: coalesce( trim(stringexpression),'')='' But it looks…
Andrus
  • 26,339
  • 60
  • 204
  • 378
283
votes
14 answers

What is null in Java?

What is null? Is null an instance of anything? What set does null belong to? How is it represented in the memory?
unj2
  • 52,135
  • 87
  • 247
  • 375
267
votes
4 answers

What is the `zero` value for time.Time in Go?

In an error condition, I tried to return nil, which throws the error: cannot use nil as type time.Time in return argument What is the zero value for time.Time?
Mingyu
  • 31,751
  • 14
  • 55
  • 60
251
votes
6 answers

Filter values only if not null using lambda in Java8

I have a list of objects say car. I want to filter this list based on some parameter using Java 8. But if the parameter is null, it throws NullPointerException. How to filter out null values? Current code is as follows requiredCars =…
vaibhavvc1092
  • 3,067
  • 4
  • 19
  • 26
249
votes
4 answers

Select rows which are not present in other table

I've got two postgresql tables: table name column names ----------- ------------------------ login_log ip | etc. ip_location ip | location | hostname | etc. I want to get every IP address from login_log which doesn't have a row in…
stUrb
  • 6,612
  • 8
  • 43
  • 71
239
votes
10 answers

Why does Oracle 9i treat an empty string as NULL?

I know that it does consider ' ' as NULL, but that doesn't do much to tell me why this is the case. As I understand the SQL specifications, ' ' is not the same as NULL -- one is a valid datum, and the other is indicating the absence of that same…
Chris R
  • 17,546
  • 23
  • 105
  • 172