Naguib Ihab
Naguib Ihab

Reputation: 4506

Obfuscating names with the same length in PostgreSQL

I have a users table in the database with a first_name column and a last_name column, I want to obfuscate the names but keep them at the same original length and upper/lower case, so for example, 'Aiden' would be 'Xxxxx' and 'Pierce' would be 'Xxxxxx'

What's the best way to do that?

Upvotes: 2

Views: 364

Answers (1)

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49270

You can use the function 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

Upvotes: 3

Related Questions