This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
HOST_NAME = "yyy.yyy.yyy.yyy" | |
DB_NAME = "postgres" | |
USER = "postgres" | |
INSERT_SQL = "/home/user/sql/insert.sql" | |
CSV_FILE = "data.csv" | |
try: | |
# CSVファイル取り込みsql実行 | |
completed_process = subprocess.run(["psql", "-h", HOST_NAME, "-U", USER, "-d", DB_NAME, "-f", INSERT_SQL, "-v", "file_name=" + CSV_FILE], stdout=subprocess.PIPE) | |
tmp = str(completed_process.stdout.splitlines()) | |
result = tmp.split(',') | |
# copyの件数 | |
#result[1] = result[1].replace('\'','').replace('b','') | |
# insertの件数 | |
result[2] = result[2].replace('\'','').replace('b','').replace(']','') | |
toroku_kensu = result[2].split() | |
print(f'登録件数:{toroku_kensu[2]}') | |
except Exception as e: | |
print(f'エラー要因:{str(e)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment