I wanted to explore the fastest way to have json generated in postgresql delivered through phoenix to the browser. With this, I wanted to completely avoid any decoding/encoding happening in ecto/phoenix since I already had perfectly valid json coming out of pg.
It took some trial and error, and some source code reading, and some help from the list but I've got it working with materialized views and returning them in less than 1ms on my laptop.
Here's the short how-to. I'm using pg 9.4 and this should work with both json and jsonb results. I've also used the generic app/App nomenclature, you'll need to change that to your app's name.
Let's take a really, really simple query that returns some json: