如何在python脚本中运行postgres命令并将其写入文件?

时间:2019-10-03 04:56:07

标签: shell python postgresql

cmd1 = 'psql -h hello.com -p 5433 -U hell_ro-d hello-c \"COPY (SELECT info1,info2,info3,info4 FROM logs_info WHERE info1 > \''+str(timing)+'\' and info1 < clock_timestamp() ORDER BY info1 desc limit 100) TO STDOUT With CSV HEADER\"  > filedetails.csv'

1 个答案:

答案 0 :(得分:0)

您可以使用os.system运行shell命令:

$ python -c 'from os import system; system("cat >/dev/stderr <<<\"shelly stuff\"")'
shelly stuff