SQLite WITH + UNION issue
I was running the query inside python 2.7.10, which comes with sqlite 3.8.3.1. It turns out that if I run this directly with the sqlite 3.8.10.2 that comes with OSX, it works fine.    

I upgraded my python sqlite to 3.9.1 and it works now.  

Instructions per trac.edgewall.org/wiki/PySqlite


Download pysqlite-2.8.1.tar.gz from
trac.edgewall.org/wiki/PySqlite
Download sqlite-amalgamation-3090100.zip from
sqlite.org/download.html  
Unzip both and put them in the same folder 
Run this command from the folder:

python setup.py build_static install 


Note: I'm using OSX El Capitain, and a separate python installation (not the built in apple one) downloaded from python.org, and my .bash_profile is set up to point to this python installation