Last active
January 13, 2021 12:43
-
-
Save simonthompson99/3218136afda7a628248eec8ed2f31e14 to your computer and use it in GitHub Desktop.
Revisions
-
simonthompson99 revised this gist
Jan 13, 2021 . No changes.There are no files selected for viewing
-
simonthompson99 created this gist
Jun 30, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ create sequence testes.test_id_seq ; create or replace function pseudo_encrypt(value int) returns int as $$ declare l1 int; l2 int; r1 int; r2 int; i int:=0; begin l1:= (value >> 16) & 65535; r1:= value & 65535; while i < 3 loop l2 := r1; r2 := l1 # ((((1366 * r1 + 150889) % 714025) / 714025.0) * 32767)::int; l1 := l2; r1 := r2; i := i + 1; end loop; return ((r1 << 16) + l1); end; $$ language plpgsql strict immutable; create table testes.id_test ( test_uid uuid not null default uuid_generate_v4(), id varchar not null default concat('sp', lpad(pseudo_encrypt(nextval('testes.test_id_seq')::int)::text, 10, '0')) );