RailsでPostgreSQLにNULLS LASTのインデックスを追加する方法

タイトルママ

nulls lastのインデックスを作りたいけどなかなか見つからなかったので書きました。

migration にこれ

add_index :table, :column, order: { column: 'DESC NULLS LAST' }

参考

PostgreSQL: Ordering, NULLs, and indexes - makandropedia

元のPostgreSQLのオプションはこちらで確認できます

https://www.postgresql.jp/document/8.3/html/sql-createindex.html