Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Check if database exists
- execute_sql(cur, "SELECT EXISTS(SELECT datname FROM pg_catalog.pg_database WHERE datname=%s);", (db, ))
- exists = cur.fetchone()[0]
- # Drop the database if it exists and it needs to be dropped
- if exists and drop_db:
- print("Dropping database '%s' because it already exists" % (db))
- execute_sql(cur, "DROP DATABASE %s;" % (db))
- #Create database
- print("Creating database '%s'" % (db))
- execute_sql(cur, "CREATE DATABASE %s;" % (db))
- # Disconnect from postgres database
- print("Closing cursor and database connection")
- close_conn(cur, conn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement