def table_exists(table_name, connection):
    """
    Check if the table exists in the database.

    :param str table_name: name of the table
    :param connection: psycopg2 connection object
    :return bool: True if the table exists, else False
    """
    cur = connection.cursor()
    query = """
        SELECT EXISTS (
            SELECT 1
            FROM information_schema.tables
            WHERE table_name = %s
        );"""
    cur.execute(query, (table_name,))
    return cur.fetchone()[0]
