usergraphtheory's picture
Sync from erdostack/bench at a7805c45d77258d316383c92bdc9f472498d255f (part 50)
29eea0a verified
Raw History Blame Contribute Delete
626 Bytes
"""Run one SQL file against the read replica and print CSV."""
import csv
import os
import sys
from pathlib import Path
def main(path):
import psycopg # imported here so the module can be loaded without the driver
with psycopg.connect(os.environ["DATABASE_URL"], autocommit=True) as conn:
conn.execute("SET default_transaction_read_only = on")
cur = conn.execute(Path(path).read_text(encoding="utf-8"))
writer = csv.writer(sys.stdout)
writer.writerow([col.name for col in cur.description])
writer.writerows(cur.fetchall())
if __name__ == "__main__":
main(sys.argv[1])