Rails Postgres 功能索引

2023-12-24

我应该如何将包含函数的多列索引输入到 schema.rb 中?

例如这不起作用:

add_index "temporary_events", ["templateinfoid", "campaign", "date(gw_out_time)", "messagetype"], :name => "temporary_events_campaign_tinfoid_date_messagetype"

耙数据库:测试:负载

耙子中止!

PGError:错误:列“日期(gw_out_time)”不存在

:在“temporary_events”上创建索引“temporary_events_campaign_tinfoid_date_messagetype”(“templateinfoid”,“campaign”,“date(gw_out_time”,“messagetype”)


用于创建索引的内置 ActiveRecord 方法(add_index)不支持功能或任何其他更高级的功能。相反,你可以使用execute使用 SQL 创建索引:

execute <<-SQL
  CREATE INDEX temporary_events_campaign_tinfoid_date_messagetype
  ON temporary_events(templateinfoid, campaign, date(gw_out_time), messagetype);
SQL

请注意,使用execute如果您不使用 SQL 模式格式(config.active_record.schema_format = :sql)。欲了解更多信息,请搜索架构格式 https://stackoverflow.com/search?q=schema_format+%5Bruby-on-rails%5D.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rails Postgres 功能索引 的相关文章

随机推荐