code: def _get_auto_increment_info(self, table):
          
          query = ''
          seq_table = ''
          seq_column = ''
          seq_name = ''
          find_query = "\n".join([
              "SELECT",
              "  t.relname as related_table,",
              "  a.attname as related_column,",
              "  s.relname as sequence_name",
              "FROM pg_class s",
              "JOIN pg_depend d ON d.objid = s.oid",
              "JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid",
              "JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)",
              "JOIN pg_namespace n ON n.oid = s.relnamespace",
              "WHERE",
              "  s.relkind = 'S'",
              "AND",
              "  n.nspname = 'public'",
              "AND",
              "  t.relname = '{}'".format(table)
          ])
  
          pipe = self._run_queries([find_query], popen_kwargs={'stdout': subprocess.PIPE})
          stdout, stderr = pipe.communicate()
          if stdout:
              try:
                  m = re.findall('^\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*$', stdout, flags=re.MULTILINE)
                  seq_table, seq_column, seq_name = m[1]
                  # http://www.postgresql.org/docs/9.2/static/functions-sequence.html
                  # http://www.postgresql.org/docs/9.2/static/functions-conditional.html
                  query = "\n".join([
                      "SELECT",
                      "  setval('{}',".format(seq_name.strip()),
                      "  coalesce(max({}), 1),".format(seq_column.strip()),
                      "  max({}) IS NOT null)".format(seq_column.strip()),
                      "FROM \"{}\"".format(seq_table.strip())
                  ])
  
              except IndexError:
                  query = ''
  
          return query, seq_table, seq_column, seq_name
docs: figure out the the autoincrement value for the given table