Example #1
0
def get_table_parents(conn,obj):
    """
        Obtiene las tablas padres de una tabla (tablas de las que hereda una tabla)
    """
    cur.execute("""
        SELECT c.oid::pg_catalog.regclass, c.relname, n.nspname
        FROM pg_catalog.pg_class c
            INNER JOIN pg_catalog.pg_inherits i ON c.oid=i.inhparent
            LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
        WHERE i.inhrelid = %s ORDER BY inhseqno
        """, [obj.oid])
    for oid, relname, namespace in cur:
        obj = Struct()
        obj.oid = oid
        obj.namespace = namespace
        obj.name = relname
        yield obj
Example #2
0
def get_oids(conn):
    cur = conn.cursor()
    cur.execute("""
        SELECT c.oid,
          n.nspname,
          c.relname
        FROM pg_catalog.pg_class c
             LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
        WHERE n.nspname != 'pg_catalog' AND pg_catalog.pg_table_is_visible(c.oid)
        ORDER BY 2, 3;
        """)
    for oid, namespace, relname in cur:
        obj = Struct()
        obj.oid = oid
        obj.namespace = namespace
        obj.name = relname
        yield obj
Example #3
0
def get_relname_oid(conn, relname):
    """
        Obtiene el OID de una relaciĆ³n (tabla, indice, pkey, etc)
    """
    cur = conn.cursor()
    cur.execute("""
        SELECT c.oid,
          n.nspname,
          c.relname
        FROM pg_catalog.pg_class c
             LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
        WHERE c.relname = %s AND pg_catalog.pg_table_is_visible(c.oid)
        ORDER BY 2, 3;
        """, [relname])
    for oid, namespace, relname in cur:
        obj = Struct()
        obj.oid = oid
        obj.namespace = namespace
        obj.name = relname
        return obj