working version of the postgres -> Redshift writer