删除SQL(Postgres)中的情况不敏感的重复项
我有一个PostgreSQL数据库,并且我正在尝试删除我表中的重复项的旧重复项(甚至仅获取ID),但只有那些是因为案例敏感性的,例如hello hello <<< /code>和
Hello
。
表非常大,我的嵌套查询需要很长时间,我想知道是否有一种更好,更有效的方法来一次进行查询,而不是将其分配到多个查询,因为其中有很多ID问题
SELECT * FROM some_table AS out
WHERE (SELECT count(*) FROM some_table AS in
WHERE out.text != in.text
AND LOWER(in.text) = LOWER(out.text)
AND in.created_at > out.created_at) > 1
谢谢!
I have a postgresql database, and I'm trying to delete (or even just get the ids) of the older of the duplicates I have in my table, but only those who are because of case sensitivity, for example helLo
and hello
.
The table is quite large and my nested query takes a really long time, I wonder if there is a better, more efficient way to do my query in one go, and not split it up to multiple queries, cause there's a lot of ids in question
SELECT * FROM some_table AS out
WHERE (SELECT count(*) FROM some_table AS in
WHERE out.text != in.text
AND LOWER(in.text) = LOWER(out.text)
AND in.created_at > out.created_at) > 1
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试一下,
然后可以将
rn
列用作过滤器Can you try
You can then use the
rn
column as a filter要帮助此查询,请创建 nofollow noreferrer“ (文本)。在索引中包括
create_at
来帮助日期比较。但是,没有您的数据,很难对此进行测试。
To help this query, create an expression index on
LOWER(text)
. Includecreated_at
in the index to help the date comparisons.It's hard to test this without your data, though.