From fbc77df84c87754204c7edf7a2911f87d7aae43b Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Fri, 24 Apr 2009 16:05:25 -0400 Subject: [PATCH] Fixed typo when the USING CAST clause was not used - the right paren was in the wrong place. Perform implicit type conversions for PG with the USING CAST clause for version PG 8.2.6 and higher (they complain about going from string to integer). --- .../connection_adapters/postgresql_adapter.rb | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 2f660a5..d83977d 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -882,11 +882,11 @@ module ActiveRecord change_column_null(table_name, column_name, false, default) if notnull end - # Patch for Postgres 8.3 and migrations that require an implicit conversion (such as :string to :integer) + # Patch for Postgres 8.2.6 and migrations that require an implicit conversion (such as :string to :integer) # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1036 def using_cast(column_name, type, options) - return "" if postgresql_version < 80300 - " USING CAST(#{quote_column_name(column_name)} AS #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}" + return "" if postgresql_version < 80206 + " USING CAST(#{quote_column_name(column_name)} AS #{type_to_sql(type, options[:limit], options[:precision], options[:scale])})" end # Changes the column of a table. @@ -896,7 +896,7 @@ module ActiveRecord begin # Patch for Postgres 8.3+ and migrations that require an implicit conversion (such as :string to :integer) # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1036 - execute "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(column_name)} TYPE #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}#{using_cast(column_name, type, options)})" + execute "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(column_name)} TYPE #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}#{using_cast(column_name, type, options)}" rescue ActiveRecord::StatementInvalid => e raise e if postgresql_version > 80000 # This is PostgreSQL 7.x, so we have to use a more arcane way of doing it. -- 1.5.4.3