lib/arjdbc/postgresql/adapter.rb
# Changes the column of a table.
Changes the column of a table.
Changes the column of a table .
def change_column(table_name, column_name, type, options = {})
      quoted_table_name = quote_table_name(table_name)
      quoted_column_name = quote_table_name(column_name)
      sql_type = type_to_sql(type, options[:limit], options[:precision], options[:scale])
      sql_type << "[]" if options[:array]
      sql = "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quoted_column_name} TYPE #{sql_type}"
      sql << " USING #{options[:using]}" if options[:using]
      if options[:cast_as]
        sql << " USING CAST(#{quoted_column_name} AS #{type_to_sql(options[:cast_as], options[:limit], options[:precision], options[:scale])})"
      end
      begin
        execute sql
      rescue ActiveRecord::StatementInvalid => e
        raise e if postgresql_version > 80000
        change_column_pg7(table_name, column_name, type, options)
      end
      change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)
      change_column_null(table_name, column_name, options[:null], options[:default]) if options.key?(:null)
    end
def change_column ( table_name , column_name , type , options = { } ) quoted_table_name = quote_table_name ( table_name ) quoted_column_name = quote_table_name ( column_name ) sql_type = type_to_sql ( type , options [ :limit ] , options [ :precision ] , options [ :scale ] ) sql_type << "[]" if options [ :array ] sql = "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quoted_column_name} TYPE #{sql_type}" sql << " USING #{options[:using]}" if options [ :using ] if options [ :cast_as ] sql << " USING CAST(#{quoted_column_name} AS #{type_to_sql(options[:cast_as], options[:limit], options[:precision], options[:scale])})" end begin execute sql rescue ActiveRecord :: StatementInvalid => e raise e if postgresql_version > 80000 change_column_pg7 ( table_name , column_name , type , options ) end change_column_default ( table_name , column_name , options [ :default ] ) if options_include_default? ( options ) change_column_null ( table_name , column_name , options [ :null ] , options [ :default ] ) if options . key? ( :null ) end
Changes the column of a table.
Changes the column of a table .
table_name
<not_specific>
column_name
<not_specific>
type
<not_specific>
options
<not_specific>