'Retrieve any constraints or keys (unique, pk, fk, check, index) across
one or more columns.'

def get_constraints(self, cursor, table_name):

    constraints = {}
    cursor.execute("\n                                                SELECT\n                                                                user_constraints.constraint_name,\n                                                                LISTAGG(LOWER(cols.column_name),    ',')    WITHIN    GROUP    (ORDER    BY    cols.position),\n                                                                CASE    user_constraints.constraint_type\n                                                                                WHEN    'P'    THEN    1\n                                                                                ELSE    0\n                                                                END    AS    is_primary_key,\n                                                                CASE\n                                                                                WHEN    user_constraints.constraint_type    IN    ('P',    'U')    THEN    1\n                                                                                ELSE    0\n                                                                END    AS    is_unique,\n                                                                CASE    user_constraints.constraint_type\n                                                                                WHEN    'C'    THEN    1\n                                                                                ELSE    0\n                                                                END    AS    is_check_constraint\n                                                FROM\n                                                                user_constraints\n                                                LEFT    OUTER    JOIN\n                                                                user_cons_columns    cols    ON    user_constraints.constraint_name    =    cols.constraint_name\n                                                WHERE\n                                                                user_constraints.constraint_type    =    ANY('P',    'U',    'C')\n                                                                AND    user_constraints.table_name    =    UPPER(%s)\n                                                GROUP    BY    user_constraints.constraint_name,    user_constraints.constraint_type\n                                ", [table_name])
    for (constraint, columns, pk, unique, check) in cursor.fetchall():
        constraints[constraint] = {'columns': columns.split(','), 'primary_key': pk, 'unique': unique, 'foreign_key': None, 'check': check, 'index': unique}
    cursor.execute("\n                                                SELECT\n                                                                cons.constraint_name,\n                                                                LISTAGG(LOWER(cols.column_name),    ',')    WITHIN    GROUP    (ORDER    BY    cols.position),\n                                                                LOWER(rcols.table_name),\n                                                                LOWER(rcols.column_name)\n                                                FROM\n                                                                user_constraints    cons\n                                                INNER    JOIN\n                                                                user_cons_columns    rcols    ON    rcols.constraint_name    =    cons.r_constraint_name    AND    rcols.position    =    1\n                                                LEFT    OUTER    JOIN\n                                                                user_cons_columns    cols    ON    cons.constraint_name    =    cols.constraint_name\n                                                WHERE\n                                                                cons.constraint_type    =    'R'    AND\n                                                                cons.table_name    =    UPPER(%s)\n                                                GROUP    BY    cons.constraint_name,    rcols.table_name,    rcols.column_name\n                                ", [table_name])
    for (constraint, columns, other_table, other_column) in cursor.fetchall():
        constraints[constraint] = {'primary_key': False, 'unique': False, 'foreign_key': (other_table, other_column), 'check': False, 'index': False, 'columns': columns.split(',')}
    cursor.execute("\n                                                SELECT\n                                                                ind.index_name,\n                                                                LOWER(ind.index_type),\n                                                                LISTAGG(LOWER(cols.column_name),    ',')    WITHIN    GROUP    (ORDER    BY    cols.column_position),\n                                                                LISTAGG(cols.descend,    ',')    WITHIN    GROUP    (ORDER    BY    cols.column_position)\n                                                FROM\n                                                                user_ind_columns    cols,    user_indexes    ind\n                                                WHERE\n                                                                cols.table_name    =    UPPER(%s)    AND\n                                                                NOT    EXISTS    (\n                                                                                SELECT    1\n                                                                                FROM    user_constraints    cons\n                                                                                WHERE    ind.index_name    =    cons.index_name\n                                                                )    AND    cols.index_name    =    ind.index_name\n                                                GROUP    BY    ind.index_name,    ind.index_type\n                                ", [table_name])
    for (constraint, type_, columns, orders) in cursor.fetchall():
        constraints[constraint] = {'primary_key': False, 'unique': False, 'foreign_key': None, 'check': False, 'index': True, 'type': ('idx' if (type_ == 'normal') else type_), 'columns': columns.split(','), 'orders': orders.split(',')}
    return constraints
