删除SQL(Postgres)中的情况不敏感的重复项

发布于 2025-01-26 00:53:51 字数 455 浏览 2 评论 0原文

我有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟柳画桥 2025-02-02 00:53:51

您可以尝试一下,

SELECT LOWER(text), ROW_NUMBER() OVER( PARTITION by LOWER(text) ORDER by created_at ) as rn
FROM some_table 

然后可以将rn列用作过滤器

Can you try

SELECT LOWER(text), ROW_NUMBER() OVER( PARTITION by LOWER(text) ORDER by created_at ) as rn
FROM some_table 

You can then use the rn column as a filter

梦一生花开无言 2025-02-02 00:53:51

要帮助此查询,请创建 nofollow noreferrer“ (文本)。在索引中包括create_at来帮助日期比较。

CREATE INDEX text_lower ON some_table(LOWER(text), created_at);

但是,没有您的数据,很难对此进行测试。

To help this query, create an expression index on LOWER(text). Include created_at in the index to help the date comparisons.

CREATE INDEX text_lower ON some_table(LOWER(text), created_at);

It's hard to test this without your data, though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文