POn Wednesday, June 8, 2016, Patrick B <patrickbakerbr@xxxxxxxxx> wrote:
ERROR: syntax error at or near "||"
LINE 12: TO '/var/lib/pgsql/' || crtrow.account_id |...
Which tells me you cannot use an _expression_ as a file name. The docs support this conclusion.
You probably need to use EXECUTE after constricting a string.
You could also try psql in a shell script.
David J.