def is_unique(conn, table, field):
    rows = query(conn, """
        SELECT information_schema.constraint_column_usage.column_name
        FROM information_schema.table_constraints
        NATURAL JOIN information_schema.constraint_column_usage
        WHERE information_schema.table_constraints.table_name=%s
          AND information_schema.constraint_column_usage.column_name=%s
          AND information_schema.table_constraints.constraint_type='UNIQUE'
        ;""", table, field['column_name'])
    return rows and True or False
Find unique columns (incomplete support)
dataset/ETHPy150Open uwdata/termite-data-server/web2py/scripts/extract_pgsql_models.py/is_unique