sql - 即将迁移 :string but I'm thinking :text might be better. 性能/目的?

标签 sql ruby string text migrate

class CreateScrapes < ActiveRecord::Migration
  def self.up
    create_table :scrapes do |t|
      t.text :saved_characters
      t.text :sanitized_characters
      t.string :href

      t.timestamps
   end
  end

  def self.down
    drop_table :scrapes
  end
end

我即将 rake db:migrate,并且正在考虑属性类型是否应该使用 textstring。由于 saved_characterssanitized_characters 将是具有数千个 unicode 值的数组,它基本上是逗号分隔的数据,我不确定 `:text' 是否真的是正确的方法这里。你会怎么办?

最佳答案

假设您使用的是 MySQL,:string:text 之间的真正区别在于长度。 Rails 对 :string 列使用 varchar 列类型,并为 :string 列设置 255 个字符的限制。 :text 令人惊讶的是,使用了 text 列。

对我来说,这表明 :string 对于您的列来说是一个非常糟糕的选择,因为它们可能超过 255 个字符。

关于sql - 即将迁移 :string but I'm thinking :text might be better. 性能/目的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4632177/

相关文章:

MySQL 在 EAV 表中按值排序?

c++ - 从文件中解压缩数据时出现段错误(使用 strtok() 和 strcpy() )?

ruby-on-rails - rails中排除和包含方法有什么用?

ruby - pretty-print 代码到 PDF

ruby-on-rails - 如何覆盖 ruby​​ 中的 [] 括号?

Python: '_io.TextIOWrapper' 类型的对象没有 len()

c++ - 如果 std::string::substr 返回 std::string_view 会有什么缺点?

sql - PL/pgSQL 函数异常

sql - 从一列而不是另一列中选择所有值的有效方法

mysql - 具有父类(super class)型表的其他 JOIN 结果的 JOIN 表