Skip to content

Instantly share code, notes, and snippets.

@tonyc
Created September 14, 2011 15:53
Show Gist options
  • Save tonyc/1216934 to your computer and use it in GitHub Desktop.
Save tonyc/1216934 to your computer and use it in GitHub Desktop.
Sequence support in PostgreSQL
require 'active_record/base'
require 'active_record/connection_adapters/abstract_adapter'
require 'active_record/connection_adapters/postgresql_adapter'
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter < AbstractAdapter
def next_sequence_value(sequence_name)
Integer(select_value("SELECT NEXTVAL('#{sequence_name}')"))
end
def prefetch_primary_key?(table_name)
true
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment