Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mlY8z-0000KA-LK for pgsql-general@arkaria.postgresql.org; Fri, 12 Nov 2021 15:07:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mlY8y-0000ad-Lc for pgsql-general@arkaria.postgresql.org; Fri, 12 Nov 2021 15:07:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mlY8y-0000aU-5F for pgsql-general@lists.postgresql.org; Fri, 12 Nov 2021 15:07:08 +0000 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mlY8w-0003aq-0c for pgsql-general@lists.postgresql.org; Fri, 12 Nov 2021 15:07:07 +0000 Received: by mail-io1-xd30.google.com with SMTP id e144so11505975iof.3 for ; Fri, 12 Nov 2021 07:07:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=uOuBKNXc48FAP8VyiBB40jDjfXgEYfuiv5mUBpUJj94=; b=lN4lKIYRhmsLwgkjIkUYCXKM4lv4GcQ1FjLGbWI2VfcXa476+uC69skiM8sFJfyQfn UdhOT7viwaLsHY43Wd0EWKciabBxtaOQb+1u/Nsrx74tbY1wCoCYygwuNHBIYwBzixBQ amwdiFaXzo2iufcWbc1zta/E60nUSQeGBWORtwS6hpzWz1z9q72h20zKfBzmUKkz/TAF zAWpChhB7mmEZ2OUYgF/Yo5FPNJWOW8QUuSa0qMprlA58B5q5B8fYMU11PnmSdB/7M7h v3h0wMpRIypSTDqGoePKxczjRoV4Ij15dtDaUJUQdmgRbSdIUsgMuybNdYgULzgSZ18o HuKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=uOuBKNXc48FAP8VyiBB40jDjfXgEYfuiv5mUBpUJj94=; b=iAAxAEohr0Jd78db9ysJj1GH3jtinpZfNP6lBwgDyinwmoOWLNtD/+sH2vRCDAlnIF FRDJUk7noOYNUPFlTY2fMZJzx0ykH3GPHUYon2CqZan6fBhFG+Q58zGldSVFDXhUMzCF 0uv8fVUOoMoupzsQW8DFl6PJidy478NsU4MOVfMtpnfZF9arAnJOcMLP63TUpKJI/xK0 m6imBDsNgfXGHR1F6pn2TtT3+5gWXJvvnbm2EyxvGg4Yh3I4l9OCJq4jgC7+nRn0osqG EBpVtYy4ZJaKXBPIle3idRSF8maxSyb0YAT5Vq9puxs91qnQ64PV88zona50yr8xYIWa bmSg== X-Gm-Message-State: AOAM5306kAFKtw3AeEdVdvgnG3T2fk/wcwwVja5n3itYwEjUQYG7wSZD oiOptfqKU513xvqJlC3G1eenZEY2Cok= X-Google-Smtp-Source: ABdhPJxGzIk+JF6Lif7KAj2zRIsKGwvS+q8CfjtcRwk6jaDa9ePrlgS1zd5XkWFYMFPCwqGwPLXVnA== X-Received: by 2002:a05:6602:2c45:: with SMTP id x5mr10922681iov.98.1636729624920; Fri, 12 Nov 2021 07:07:04 -0800 (PST) Received: from [10.0.0.94] (c-73-63-59-118.hsd1.ut.comcast.net. [73.63.59.118]) by smtp.gmail.com with ESMTPSA id j13sm4327667ila.6.2021.11.12.07.07.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Nov 2021 07:07:04 -0800 (PST) Subject: Re: Replace anonymized data in string To: pgsql-general@lists.postgresql.org References: From: Rob Sargent Message-ID: <252c3b66-cfa1-d305-0341-c5a4b590f476@gmail.com> Date: Fri, 12 Nov 2021 08:07:03 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------1E7E6FCD47113F0077166A9B" Content-Language: en-CA List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------1E7E6FCD47113F0077166A9B Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit On 11/12/21 7:12 AM, Patrick FICHE wrote: > > Hi Team, > > I have some data that has been anonymized and I would like to generate > some test data from this. In some way, I would like to deanonymize > this data with random data. > > For example, phone numbers have been anonymized with changing the 5 > right digits with the 8 digit (preserving length). > > Applying this, the number 390694802756 was changed to 3906948088888. > > I would like to get random digits at the end of the phone number > knowing that anonymized data can be a variable length. > > So, I would like to change every sequence (at least 2) of 8 by random > value of same length (I don’t worry if phone number contains 88 in the > middle and this sequence is changed to random data)… > > I tried to do this with replace / regexp_replace functions but could > not achieve what I wanted to do. > > I don’t want these digits to be changed with a single one (88888 by > 111111 or 99999 but something like 42384)… > > Ideally, the new string would be different if multiple sequences of 8 > appear in a string and would be different from one record to the other > when applied to a full table… > > Is there any way to do this ? > > Thanks, > > Patrick > Usual trick it to select floor(random()*100000); --------------1E7E6FCD47113F0077166A9B Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: 8bit
On 11/12/21 7:12 AM, Patrick FICHE wrote:

Hi Team,

 

I have some data that has been anonymized and I would like to generate some test data from this. In some way, I would like to deanonymize this data with random data.

 

For example, phone numbers have been anonymized with changing the 5 right digits with the 8 digit (preserving length).

Applying this, the number 390694802756 was changed to 3906948088888.

 

I would like to get random digits at the end of the phone number knowing that anonymized data can be a variable length.

So, I would like to change every sequence (at least 2) of 8 by random value of same length (I don’t worry if phone number contains 88 in the middle and this sequence is changed to random data)…

 

I tried to do this with replace / regexp_replace functions but could not achieve what I wanted to do.

I don’t want these digits to be changed with a single one (88888 by 111111 or 99999 but something like 42384)…

Ideally, the new string would be different if multiple sequences of 8 appear in a string and would be different from one record to the other when applied to a full table…

 

Is there any way to do this ?

 

Thanks,

Patrick

Usual trick it to select floor(random()*100000);
--------------1E7E6FCD47113F0077166A9B--