From 37edf4dcb0b684e14fff9738e50299f363a37662 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 7 Jan 2016 17:22:11 -0600 Subject: [PATCH] Add Is It Null Or Not Null as a postgres til. --- README.md | 1 + postgres/is-it-null-or-not-null.md | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 postgres/is-it-null-or-not-null.md diff --git a/README.md b/README.md index 9c101b2..77ce5f1 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Insert Just The Defaults](postgres/insert-just-the-defaults.md) - [Integers In Postgres](postgres/integers-in-postgres.md) - [Intervals Of Time By Week](postgres/intervals-of-time-by-week.md) +- [Is It Null Or Not Null?](postgres/is-it-null-or-not-null.md) - [Limit Execution Time Of Statements](postgres/limit-execution-time-of-statements.md) - [List All Columns Of A Specific Type](postgres/list-all-columns-of-a-specific-type.md) - [List All Versions Of A Function](postgres/list-all-versions-of-a-function.md) diff --git a/postgres/is-it-null-or-not-null.md b/postgres/is-it-null-or-not-null.md new file mode 100644 index 0000000..c27606f --- /dev/null +++ b/postgres/is-it-null-or-not-null.md @@ -0,0 +1,25 @@ +# Is It Null Or Not Null? + +In PostgreSQL, the standard way to check if something is `NULL` is like so: + +```sql +select * as wild_pokemons from pokemons where trainer_id is null; +``` + +To check if something is not null, you just add `not`: + +```sql +select * as captured_pokemons from pokemons where trainer_id is not null; +``` + +PostgreSQL also comes with `ISNULL` and `NOTNULL` which are non-standard +ways of doing the same as above: + + +```sql +select * as wild_pokemons from pokemons where trainer_id isnull; +``` + +```sql +select * as captured_pokemons from pokemons where trainer_id notnull; +```