CREATE EXTENSION IF NOT EXISTS anon CASCADE; NOTICE: installing required extension "tsm_system_rows" SELECT anon.load(); load ------ (1 row) -- -- Generic Types -- -- zip SELECT pg_typeof(anon.random_zip()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) -- string SELECT pg_typeof(anon.random_string(1)) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) --SELECT anon_string(123456789); -- Date SELECT pg_typeof(anon.random_date_between('1900-01-01'::TIMESTAMP WITH TIME ZONE,now())) = 'TIMESTAMP WITH TIME ZONE'::REGTYPE; ?column? ---------- t (1 row) SELECT pg_typeof(anon.random_date_between('0001-01-01'::DATE,'4001-01-01'::DATE)) = 'TIMESTAMP WITH TIME ZONE'::REGTYPE; ?column? ---------- t (1 row) SELECT pg_typeof(anon.random_date()) = 'TIMESTAMP WITH TIME ZONE'::REGTYPE; ?column? ---------- t (1 row) -- Integer SELECT pg_typeof(anon.random_int_between(1,3)) = 'INTEGER'::REGTYPE; ?column? ---------- t (1 row) -- -- Personal Data (First Name, etc.) -- -- First Name SELECT pg_typeof(anon.random_first_name()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) -- Last Name SELECT pg_typeof(anon.random_last_name()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) -- Email SELECT pg_typeof(anon.random_email()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) -- Phone SELECT pg_typeof(anon.random_phone('0033')) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) SELECT anon.random_phone(NULL) IS NULL; ?column? ---------- t (1 row) SELECT pg_typeof(anon.random_phone()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) -- Location SELECT pg_typeof(anon.random_city_in_country('France')) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) SELECT anon.random_city_in_country('dfndjndjnjdnvjdnjvndjnvjdnvjdnjnvdnvjdnvj') IS NULL; ?column? ---------- t (1 row) SELECT anon.random_city_in_country(NULL) IS NULL; ?column? ---------- t (1 row) SELECT pg_typeof(anon.random_city()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) SELECT pg_typeof(anon.random_region_in_country('Italy')) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) SELECT anon.random_region_in_country('c,dksv,kdfsdnfvsjdnfjsdnjfndj') IS NULL; ?column? ---------- t (1 row) SELECT anon.random_region_in_country(NULL) IS NULL; ?column? ---------- t (1 row) SELECT pg_typeof(anon.random_region()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) SELECT pg_typeof(anon.random_country()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) -- -- Company -- SELECT pg_typeof(anon.random_company()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) -- -- IBAN -- SELECT pg_typeof(anon.random_iban()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) -- -- SIRET -- SELECT pg_typeof(anon.random_siret()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) SELECT pg_typeof(anon.random_siren()) = 'TEXT'::REGTYPE; ?column? ---------- t (1 row) ------------------------------------------------------------------------------- -- Masking ------------------------------------------------------------------------------- CREATE TEMPORARY TABLE t1 ( id SERIAL, name TEXT, "CreditCard" TEXT, fk_company INTEGER ); INSERT INTO t1 VALUES (1,'Schwarzenegger','1234567812345678', 1991); COMMENT ON COLUMN t1.name IS ' MASKED WITH ( FUNCTION = random_last_name() )'; COMMENT ON COLUMN t1."CreditCard" IS ' MASKED WITH ( FUNCTION = random_string(12) )'; CREATE TEMPORARY TABLE "T2" ( id_company SERIAL, "IBAN" TEXT, COMPANY TEXT ); INSERT INTO "T2" VALUES (1991,'12345677890','Skynet'); COMMENT ON COLUMN "T2"."IBAN" IS 'MASKED WITH (FUNCTION=random_iban())'; COMMENT ON COLUMN "T2".COMPANY IS 'jvnosdfnvsjdnvfskngvknfvg MASKED WITH (FUNCTION = random_company() ) jenfksnvjdnvkjsnvsndvjs'; SELECT count(*) = 4 FROM anon.mask; ?column? ---------- t (1 row) SELECT func = 'random_iban()' FROM anon.mask WHERE attname = 'IBAN'; ?column? ---------- t (1 row) SELECT anon.anonymize_all_the_things(); NOTICE: ANONYMIZE ALL THE THINGS \o/ NOTICE: Anon t1.name with anon.random_last_name() NOTICE: Anon t1.CreditCard with anon.random_string(12) NOTICE: Anon T2.IBAN with anon.random_iban() NOTICE: Anon T2.company with anon.random_company() anonymize_all_the_things -------------------------- (0 rows) SELECT company != 'skynet' FROM "T2" WHERE id_company=1991; ?column? ---------- t (1 row) SELECT name != 'Schwarzenegger' FROM t1 WHERE id = 1; ?column? ---------- t (1 row) ------------------------------------------------------------------------------- -- End ------------------------------------------------------------------------------- SELECT anon.unload(); unload -------- (1 row) DROP EXTENSION anon;