code/prototype/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/postgresql/schema_statements.rb
# Resets the sequence of a table's primary key to the maximum value.
Resets the sequence of a table's primary key to the maximum value.
Resets the sequence of a table ' s primary key to the maximum value .
def reset_pk_sequence!(table, pk = nil, sequence = nil) 
          unless pk and sequence
            default_pk, default_sequence = pk_and_sequence_for(table)
            pk ||= default_pk
            sequence ||= default_sequence
          end
          if @logger && pk && !sequence
            @logger.warn "#{table} has primary key #{pk} with no default sequence."
          end
          if pk && sequence
            quoted_sequence = quote_table_name(sequence)
            max_pk = select_value("select MAX(#{quote_column_name pk}) from #{quote_table_name(table)}")
            if max_pk.nil?
              if postgresql_version >= 100000
                minvalue = select_value("SELECT seqmin from pg_sequence where seqrelid = '#{quoted_sequence}'::regclass")
              else
                minvalue = select_value("SELECT min_value FROM #{quoted_sequence}")
              end
            end
            select_value(<<-end_sql, "SCHEMA")
              SELECT setval('#{quoted_sequence}', #{max_pk ? max_pk : minvalue}, #{max_pk ? true : false})
            end_sql
          end
        end
def reset_pk_sequence! ( table , pk = nil , sequence = nil ) unless pk and sequence default_pk , default_sequence = pk_and_sequence_for ( table ) pk ||= default_pk sequence ||= default_sequence end if @logger && pk && ! sequence @logger . warn "#{table} has primary key #{pk} with no default sequence." end if pk && sequence quoted_sequence = quote_table_name ( sequence ) max_pk = select_value ( "select MAX(#{quote_column_name pk}) from #{quote_table_name(table)}" ) if max_pk . nil? if postgresql_version >= 100000 minvalue = select_value ( "SELECT seqmin from pg_sequence where seqrelid = '#{quoted_sequence}'::regclass" ) else minvalue = select_value ( "SELECT min_value FROM #{quoted_sequence}" ) end end select_value ( <<-end_sql , "SCHEMA" ) 
              SELECT setval(' #{ quoted_sequence } ',  #{ max_pk ? max_pk : minvalue } ,  #{ max_pk ? true : false } )
             end_sql end end
Resets the sequence of a table's primary key to the maximum value.
Resets the sequence of a table ' s primary key to the maximum value .
#:nodoc:
table
<not_specific>
pk
<not_specific>
sequence
<not_specific>