I have some columns with PII that I need to share with a coworker. They need to be able to see 50% of the characters and the other 50% should be replaced by Asterisks, but I dont know how to do it.
Also, would you use a table or a view to do this? Do you have any advice? I’m pretty new in SQL.
So far, my code is something like this:
CREATE TABLE clients (
client_id INT NOT NULL,
mail VARCHAR(30) NOT NULL,
phone INT NOT NULL,
PRIMARY KEY (client_id)
);
INSERT INTO clients VALUES
(1,'[email protected]',23234123),
(2,'[email protected]',23235543),
(3,'[email protected]',343435523);
CREATE VIEW clients_partial as (
SELECT client_id,
mail as mail_partial, #### PROBLEM TO SOLVE
phone as phone_partial ### PROBLEM TO SOLVE
FROM clients);
SELECT * FROM clients_partial
What I have in clients_partial:
What I need in clients_partial:
2
Answers
Determine length of string
Extract first xx characters
Pad that with asterisks to the length of the string
Adjust as needed.
It is not completely identical, but to anonymize it should be good
fiddle