That SQL looks pretty complicated  Where are the tests  James E Marca mp4
Channel: Postgres Conference
Date: 19/07/2016

My standard development technique with PostgreSQL is to hack away in Emacs, try things out on live data, and eventually build up working queries and functions. This "test as you go" approach works well for small projects, but for really hard problems the result is usually hundreds of lines of SQL that looks a lot like an object lesson in unmaintainable code.

http://www.pgconf.us/2016/event/146/that-sql-looks-pretty-complicated-where-are-the-tests/