【问题标题】:PostgreSQL - Check column value and update after removing any symbolsPostgreSQL - 检查列值并在删除任何符号后更新
【发布时间】:2015-03-13 11:28:14
【问题描述】:

我在“用户”表中有大量数据。 “用户名”字段包含字符串值,但用户在其中有输入符号,例如im-a-user、you_are_user 等

如何使用 SQL 查询清理这些列数据?

用户:

我想清理用户名列中的值,使它们看起来像 imauser、imanotheruser 和 andmoreuser 等。

【问题讨论】:

标签: database postgresql sql-update


【解决方案1】:

使用regexp_replace()

select id, 
       regexp_replace(lower(username), '[^a-z]', '', 'gi') as clean_user_name
from users;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-14
    • 2013-04-04
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2015-04-17
    相关资源
    最近更新 更多