Hi @andatki,
This is a follow-up to my previous error report, High Performance PostgreSQL for Rails: Confusing `SUBSTR` arguments in `SCRUB_EMAIL` (page 52). The + 1 after GREATEST(…) was necessary when we were passing 0 as the start index to SUBSTR, but now it’s incorrect and results in a scrubbed email address that is one character too long when the original email username has a length greater than or equal to 5. The example on Page 53 actually demonstrates the bug:
SELECT SCRUB_EMAIL('bob-and-jane@gmail.com');
-- scrub_email
-- ------------------------
-- 2bffb502c463@gmail.com
“bob-and-jane@gmail.com” has length 22, whereas “2bffb502c463@gmail.com” has length 23:
owner@localhost:5432 rideshare_development# SELECT LENGTH('bob-and-jane@gmail.com'), LENGTH(SCRUB_EMAIL('bob-and-jane@gmail.com'));
length | length
--------+--------
22 | 23
(1 row)
Thank you,
Doug