def check_database(con, dbname):
    """Check a database exists in a given connection"""
    cur = con.cursor()
    sql = """SELECT 0 FROM pg_database WHERE datname = '%s'"""
    cur.execute(sql % dbname)
    result = cur.fetchall()
    if result:
        return(True)
    else:
        return(False)