def table_exists ( cursor , tablename , schema = 'public' ) : query = """
    SELECT EXISTS (
        SELECT 1
        FROM information_schema.tables
        WHERE table_schema = %s
        AND table_name = %s
    )""" cursor . execute ( query , ( schema , tablename ) ) res = cursor . fetchone ( ) [ 0 ] return res
if table exists python
def table_exists(cursor, tablename, schema='public'):
    query = """
    SELECT EXISTS (
        SELECT 1
        FROM information_schema.tables
        WHERE table_schema = %s
        AND table_name = %s
    )"""
    cursor.execute(query, (schema, tablename))
    res = cursor.fetchone()[0]
    return res