Method: Sequel::Postgres::DatabaseMethods#primary_key_sequence

Defined in:
lib/sequel/adapters/shared/postgres.rb

#primary_key_sequence(table, opts = OPTS) ⇒ Object

Return the sequence providing the default for the primary key for the given table.

[View source]

696
697
698
699
700
701
702
703
704
705
706
707
# File 'lib/sequel/adapters/shared/postgres.rb', line 696

def primary_key_sequence(table, opts=OPTS)
  quoted_table = quote_schema_table(table)
  Sequel.synchronize{return @primary_key_sequences[quoted_table] if @primary_key_sequences.has_key?(quoted_table)}
  cond = {Sequel[:t][:oid] => regclass_oid(table, opts)}
  value = if pks = _select_serial_sequence_ds.first(cond)
    literal(SQL::QualifiedIdentifier.new(pks[:schema], pks[:sequence]))
  elsif pks = _select_custom_sequence_ds.first(cond)
    literal(SQL::QualifiedIdentifier.new(pks[:schema], LiteralString.new(pks[:sequence])))
  end

  Sequel.synchronize{@primary_key_sequences[quoted_table] = value} if value
end