Is there any way to capture shell output (in a psql variable) and/or the exit code of running a shell command from inside psql
using \!
? The documentation provides no details.
\!
with \o
..You can combine the two like this,
\! echo "SELECT 1;" > bar
(runs the command echo "SELECT 1;"
redirects output of SELECT 1;
to bar
)\o bar
(runs the commands in bar
)Seems to be impossible for \!
,
but one can set a variable from external command output,
testdb=> \set content `cat my_file.txt`
and then using this var in sql expression like this:
testdb=> INSERT INTO my_table VALUES (:'content');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With