Memory/performance optimizations, LINQ fixes.

Reuse existing stream reader/writer instead of creating new instances.
Initialize reader/writer eagerly since ChunkedMemoryStream is pooled.

Added brackets around coalesce since it can be used as an object.
Optimizations with array for loops instead of foreach loops.

Changed bytea escaping to match Postgres when empty bytea