I have been working with a lot of ETL stuff lately and have to import/export data from our postgresql database frequently.
While writing a script recently, I found that psql doesn’t allow using the
directive with a multi line SQL when it is passed to the
The only workaround seemed to be squishing the sql into a single line.
However, this makes it very difficult to read and modify the SQL. This is when bash came to my rescue :)
Here is a hacky way to do use multiline SQL with
This just strips the newlines before sending it to psql. Have your cake and eat it too :)