我的数据库中有一个 users
表,其中包含 first_name
列和 last_name
列,我想混淆名称但保留它们具有相同的原始长度和大小写,因此,例如,“Aiden”将是“Xxxxx”,“Pierce”将是“Xxxxxx”
最好的方法是什么?
最佳答案
您可以使用函数REPEAT
.
select
case when initcap(first_name)=first_name then initcap(repeat('x',length(first_name))) else repeat('x',length(first_name)) end,
case when initcap(last_name)=last_name then initcap(repeat('x',length(last_name))) else repeat('x',length(last_name)) end
from tablename
关于sql - 在 PostgreSQL 中混淆相同长度的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44013263/