Skip to content

Instantly share code, notes, and snippets.

@andersondias
Last active January 6, 2016 05:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersondias/2fa15022b839ba9a752d to your computer and use it in GitHub Desktop.
Save andersondias/2fa15022b839ba9a752d to your computer and use it in GitHub Desktop.
Ordering by nulls on Postgres
-- Default order will return NULL values at
-- the end of list
SELECT value FROM example ORDER BY value;
------------
-- value --
------------
-- 1 --
-- 2 --
-- 3 --
-- NULL --
------------
-- Ordering using the NULLS FIRST option will return
-- the list with NULL values in the beginning.
SELECT value FROM example ORDER BY value NULLS FIRST;
------------
-- value --
------------
-- NULL --
-- 1 --
-- 2 --
-- 3 --
------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment