diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-05-12 16:39:24 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-05-12 16:39:24 +0200 |
commit | 711af752342cdd558f5f82d407d0d56a115bb8bc (patch) | |
tree | fb9e61741921e303e6dfbc233875dcfebf382159 /activerecord | |
parent | 4320b77804e090ff8415dbbc79dde6c391f09c7c (diff) | |
download | rails-711af752342cdd558f5f82d407d0d56a115bb8bc.tar.gz rails-711af752342cdd558f5f82d407d0d56a115bb8bc.tar.bz2 rails-711af752342cdd558f5f82d407d0d56a115bb8bc.zip |
pg, map `char` and `name` types as string. [dark-panda & Yves Senn]
Closes #10802.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 9 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/datatype_test.rb | 23 |
3 files changed, 33 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index f44549ca45..b5eb22773a 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,12 @@ +* Handle `name` and `"char"` column types in the PostgreSQL adapter. + + `name` and `"char"` are special character types used internally by + PostgreSQL and are used by internal system catalogs. These field types + can sometimes show up in structure-sniffing queries that feature internal system + structures or with certain PostgreSQL extensions. + + *J Smith*, *Yves Senn* + * Fix `PostgreSQLAdapter::OID::Float#type_cast` to convert Infinity and NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN` diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb index 14beb7bd25..b173163e41 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb @@ -409,6 +409,7 @@ This is not reliable and will be removed in the future. register_type 'text', OID::Text.new register_type 'varchar', OID::String.new alias_type 'char', 'varchar' + alias_type 'name', 'varchar' alias_type 'bpchar', 'varchar' register_type 'bool', OID::Boolean.new register_type 'bit', OID::Bit.new diff --git a/activerecord/test/cases/adapters/postgresql/datatype_test.rb b/activerecord/test/cases/adapters/postgresql/datatype_test.rb index 331481cb10..3d96c7b0ee 100644 --- a/activerecord/test/cases/adapters/postgresql/datatype_test.rb +++ b/activerecord/test/cases/adapters/postgresql/datatype_test.rb @@ -1,4 +1,5 @@ require "cases/helper" +require 'support/ddl_helper' class PostgresqlArray < ActiveRecord::Base end @@ -315,3 +316,25 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase @connection.reconnect! end end + +class PostgresqlInternalDataTypeTest < ActiveRecord::TestCase + include DdlHelper + + setup do + @connection = ActiveRecord::Base.connection + end + + def test_name_column_type + with_example_table @connection, 'ex', 'data name' do + column = @connection.columns('ex').find { |col| col.name == 'data' } + assert_equal :string, column.type + end + end + + def test_char_column_type + with_example_table @connection, 'ex', 'data "char"' do + column = @connection.columns('ex').find { |col| col.name == 'data' } + assert_equal :string, column.type + end + end +end |