Skip to content

Instantly share code, notes, and snippets.

@sergeykish
Created September 22, 2010 14:27
Show Gist options
  • Save sergeykish/591765 to your computer and use it in GitHub Desktop.
Save sergeykish/591765 to your computer and use it in GitHub Desktop.
order by null
test=# create table nullorder (created_at timestamp);
CREATE TABLE
test=# insert into nullorder (created_at) values (null), (null), ('1999-01-08 04:05:06'), ('1999-11-08 04:05:06'), (null);
INSERT 0 5
test=# select * from nullorder;
created_at
---------------------
1999-01-08 04:05:06
1999-11-08 04:05:06
(5 rows)
test=# select * from nullorder order by created_at is null DESC, created_at;
created_at
---------------------
1999-01-08 04:05:06
1999-11-08 04:05:06
(5 rows)
test=# select * from nullorder order by created_at = null DESC, created_at;
created_at
---------------------
1999-01-08 04:05:06
1999-11-08 04:05:06
(5 rows)
test=# select * from nullorder order by isnull(created_at) DESC, created_at;
ERROR: function isnull(timestamp without time zone) does not exist
LINE 1: select * from nullorder order by isnull(created_at) DESC, cr...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment