Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1.     # Check if database exists
  2.     execute_sql(cur, "SELECT EXISTS(SELECT datname FROM pg_catalog.pg_database WHERE datname=%s);", (db, ))
  3.     exists = cur.fetchone()[0]
  4.  
  5.     # Drop the database if it exists and it needs to be dropped
  6.     if exists and drop_db:
  7.         print("Dropping database '%s' because it already exists" % (db))
  8.         execute_sql(cur, "DROP DATABASE %s;" % (db))
  9.  
  10.     #Create database
  11.     print("Creating database '%s'" % (db))
  12.     execute_sql(cur, "CREATE DATABASE %s;" % (db))
  13.  
  14.     # Disconnect from postgres database
  15.     print("Closing cursor and database connection")
  16.     close_conn(cur, conn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement