如何在bash变量上存储标量postgresql值,如下面的脚本所示?
dbname="testlauf"
username="postgres"
vartest='psql -c -d $dbname -U $username -h localhost -p 5432 "SELECT gid FROM testtable WHERE aid='1';"'
echo "$vartest"
我试过几篇不同的文章,但似乎都不管用.提前谢谢.
如何在bash变量上存储标量postgresql值,如下面的脚本所示?
dbname="testlauf"
username="postgres"
vartest='psql -c -d $dbname -U $username -h localhost -p 5432 "SELECT gid FROM testtable WHERE aid='1';"'
echo "$vartest"
我试过几篇不同的文章,但似乎都不管用.提前谢谢.
把-c
选项放在它的参数前面——查询.请注意,使用附加的-t
选项只获取元组值.当然,使用backticks(`)操作符.
还建议使用-X
选项,因为有时.psqlrc
文件可能会添加一些冗余输出,-A
选项也会禁用列对齐(空白).
要跳过通知或其他附加消息,请包含-q
标志.
vartest=`psql -d $db -U $user -AXqtc "SELECT gid FROM testtable WHERE aid='1'"`