Permalink
Browse files

pg, map `char` and `name` types as string. [dark-panda & Yves Senn]

Closes #10802.
  • Loading branch information...
1 parent 4320b77 commit 711af752342cdd558f5f82d407d0d56a115bb8bc @senny senny committed May 12, 2014
@@ -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`
@@ -409,6 +409,7 @@ def self.registered_type?(name)
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
@@ -1,4 +1,5 @@
require "cases/helper"
+require 'support/ddl_helper'
class PostgresqlArray < ActiveRecord::Base
end
@@ -315,3 +316,25 @@ def test_timestamp_with_zone_values_without_rails_time_zone_support
@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

0 comments on commit 711af75

Please sign in to comment.