Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何修复PG::programlimited:错误?_Ruby On Rails_Postgresql_Indexing_Ruby On Rails 4.1 - Fatal编程技术网

Ruby on rails 如何修复PG::programlimited:错误?

Ruby on rails 如何修复PG::programlimited:错误?,ruby-on-rails,postgresql,indexing,ruby-on-rails-4.1,Ruby On Rails,Postgresql,Indexing,Ruby On Rails 4.1,我创建了一个表,并在其中添加了以下索引: add_index :answers, [:output, :question_id], unique: true 索引允许通过其输出和问题id快速查找答案。创建多个答案时,我遇到以下错误: PG::ProgramLimitExeded:错误:索引行大小3088超过了索引的最大值2712 “索引关于输出和问题id的答案” 提示:大于缓冲区页1/3的值不能被索引。 考虑一个MD5哈希值的函数索引,或者使用全文索引。 如何解决此问题?我可以将唯一性方面移到

我创建了一个表,并在其中添加了以下索引:

add_index :answers, [:output, :question_id], unique: true
索引允许通过其输出和问题id快速查找答案。创建多个答案时,我遇到以下错误:

PG::ProgramLimitExeded:错误:索引行大小3088超过了索引的最大值2712
“索引关于输出和问题id的答案”
提示:大于缓冲区页1/3的值不能被索引。
考虑一个MD5哈希值的函数索引,或者使用全文索引。
如何解决此问题?我可以将唯一性方面移到模型中,但索引很重要。Rails支持创建MD5散列值吗

这是Postgres提出的错误。它抱怨您应该索引md5(giant_string)或沿着这些行的某些内容(在您的例子中,我想象一个答案位置字段),而不是直接索引giant_string,因为索引这么大的字符串并没有那么有用。

现在,我只是避免保存任何大于2700个字符的记录。