您可以将shell命令的结果存储在这样的
psql变量中:
set afile `echo "$outputdir/a.csv"`COPY (SELECt * FROM a) TO :'afile';
您的案例的一个例子是:
set outputdir '/path/to/output'set afile :outputdir '/a.csv'COPY (SELECt * FROM a) TO :'afile';
请注意,在示例中,您需要在脚本文件中设置变量,但是如果在调用时设置了第一行,则可以跳过第一行
psql:
psql --set=outputdir="$outputdir" <conn parameters> -f /path/to/yourscript.sql



