def fix_primary_keys(self):
        cu = self.db.cursor()
        # get the name of the primary key
        cu.execute("""
        select
            t.relname as table_name,
            col.attname as column_name
        from pg_class t
        join pg_index i on t.oid = i.indrelid and i.indisprimary = true
        join pg_class ind on i.indexrelid = ind.oid
        join pg_attribute col on col.attrelid = t.oid and col.attnum = i.indkey[0]
        where i.indnatts = 1
          and pg_catalog.pg_table_is_visible(t.oid)
        """)
        for (t, col) in cu.fetchall():
            table = t.lower()
            cu.execute("select pg_catalog.pg_get_serial_sequence(?, ?)", (table, col))
            seqname = cu.fetchone()[0]
            if seqname is None:
                # this primary key does not have a sequence associated with it
                continue
            # get the max seq value
            cu.execute("select max(%s) from %s" % (col, table))
            seqval = cu.fetchone()[0]
            if not seqval:
                seqval = 1
            else:
                seqval += 1 # we need the next one in line
            # now reset the sequence for the primary key
            cu.execute("select pg_catalog.setval(?, ?, false)", (seqname, seqval))
            ret = cu.fetchone()[0]
            assert (ret == seqval)
            if self.verbose:
                print (seqname, ret, table, col) % "SETVAL %s = %d (%s.%s)"
    # functions for when the instance is a target
dataset/ETHPy150Open sassoftware/conary/scripts/migration/database.py/PgSQLDatabase.fix_primary_keys/swapped operands of `%`