Skip to content

Instantly share code, notes, and snippets.

@karol-blaszczyk
Created November 4, 2019 16:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karol-blaszczyk/3fcd4234e777412413c6afe7d8dd2044 to your computer and use it in GitHub Desktop.
Save karol-blaszczyk/3fcd4234e777412413c6afe7d8dd2044 to your computer and use it in GitHub Desktop.
## Connect PG8000 to database
conn = pg8000.connect(database=args['db_name'],user=args['db_user'],password=args['db_password'],host=args['db_host'],port=5432)
cur = conn.cursor()
# ...
# Example upsert query
cur.execute("INSERT INTO {} SELECT * FROM {} ON CONFLICT (id) DO UPDATE SET name = EXCLUDED.name".format('campaigns', 'tmp_staging_campaings'))
# ...
conn.commit()
cur.close()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment