[postgis-users] Can we treat a large block of psql codes as a string and execute the string?

Giuseppe Broccolo g.broccolo.7 at gmail.com
Tue Apr 21 15:08:18 PDT 2020


Hi Shao,

Maybe you are looking about how to pass SQL statements via a shell
here-document:

psql [options] <<EOF
SELECT *
FROM foo1
WHERE col='val';

SELECT * FROM foo2;
EOF

Eventual bash variable within the here-document can be interpolated.
To avoid that just quote the first instance of EOF

psql [options] <<'EOF'
SELECT *
FROM foo1
WHERE col='val';

SELECT * FROM foo2;
EOF


Il giorno mar 21 apr 2020 alle ore 21:16 Shaozhong SHI <
shishaozhong at gmail.com> ha scritto:

> It is quite appealing to wrap up a large block of psql codes as a string
> and execute the string.
>
> And, how to deal with quotes within quotes.
>
> I tried short text strings.  It worked well, but it does not seem to work
> with very long strings in different lines.
>
> Can anyone shed light on this?
>
> Regards,
>
> Shao
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20200421/421256f7/attachment.html>


More information about the postgis-users mailing list