Home Postgres 使用hashindex之后,rails的upsert_all无法生效的问题:
Post
Cancel

Postgres 使用hashindex之后,rails的upsert_all无法生效的问题:

refer to:
https://stackoverflow.com/questions/44274080/postgres-hash-index-with-unique-constraint

https://stackoverflow.com/questions/469471/how-do-i-alter-a-postgresql-table-and-make-a-column-unique

No unique index found for xx...

这个时候要注意了,postgres 的默认索引是有 btree, 是有unique 约束的,但是hash索引则没有。

自己摸索出来的办法: 使用

psql=# alter table udts add constraint unique_type_hash unique (type_hash);

就可以实现了

删除某个constraint/ index:

ALTER TABLE your_schema.your_table DROP CONSTRAINT constraint_name;

This post is licensed under CC BY 4.0 by the author.
Contents