Method: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#datetime_type

Defined in:
lib/active_record/connection_adapters/postgresql_adapter.rb

#datetime_typeObject

:singleton-method: PostgreSQL supports multiple types for DateTimes. By default, if you use datetime in migrations, Rails will translate this to a PostgreSQL “timestamp without time zone”. Change this in an initializer to use another NATIVE_DATABASE_TYPES. For example, to store DateTimes as “timestamp with time zone”:

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :timestamptz

Or if you are adding a custom type:

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:my_custom_type] = { name: "my_custom_type_name" }
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :my_custom_type

If you’re using :ruby as your config.active_record.schema_format and you change this setting, you should immediately run bin/rails db:migrate to update the types in your schema.rb.



123
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 123

class_attribute :datetime_type, default: :timestamp