-
Notifications
You must be signed in to change notification settings - Fork 8
Description
In SELECT hashids.encode_list(
<p_numbers bigint[]>,
<p_salt text>,
<p_min_hash_length integer>,
<p_alphabet text>,
<p_zero_offset boolean>
)
Not sure if this is a POSTGRES error or what but when I run my code with a limit above 4 bytes on the integer array input I get an integer out of range error from line 48:
raise notice '%[%]: % for %', p_numbers, v_i, v_number, v_count;
My code as follows:
sDateTime := to_char(NOW()::timestamp, 'YYYY-MM-DD HH24:MI:SS.MS');
RAISE NOTICE 'DateTime is: %', sDateTime;
iBigLimit := 92233720368547757;
sSalt := 'G Salt';
FOR i IN 1..length(sDateTime) LOOP
ch := SUBSTRING ( sDateTime ,i , 1 );
IF iBig < 1 THEN
iBig = ascii(ch);
ELSE
iBig := iBig*100 + ascii(ch);
END IF;
RAISE NOTICE 'ch is : %, %', ch, iBig;
IF iBig > iBigLimit THEN
iBigArr := array_append(iBigArr, iBig);
iBig := 0;
END IF;
END LOOP;
IF iBig > 0 THEN --Need to do this otherwise we miss the last digits
iBigArr := array_append(iBigArr, iBig);
END IF;
RAISE NOTICE 'iBigArr is: %', iBigArr;
sHash := hashids."encode_list"(iBigArr, sSalt,1);
RAISE NOTICE 'Hash is: %', sHash;
SQL output is:
NOTICE: DateTime is: 2020-08-25 21:25:02.103
NOTICE: ch is : 2, 50
NOTICE: ch is : 0, 5048
NOTICE: ch is : 2, 504850
NOTICE: ch is : 0, 50485048
NOTICE: ch is : -, 5048504845
NOTICE: ch is : 0, 504850484548
NOTICE: ch is : 8, 50485048454856
NOTICE: ch is : -, 5048504845485645
NOTICE: ch is : 2, 504850484548564550
NOTICE: ch is : 5, 53
NOTICE: ch is : , 5332
NOTICE: ch is : 2, 533250
NOTICE: ch is : 1, 53325049
NOTICE: ch is : :, 5332504958
NOTICE: ch is : 2, 533250495850
NOTICE: ch is : 5, 53325049585053
NOTICE: ch is : :, 5332504958505358
NOTICE: ch is : 0, 533250495850535848
NOTICE: ch is : 2, 50
NOTICE: ch is : ., 5046
NOTICE: ch is : 1, 504649
NOTICE: ch is : 0, 50464948
NOTICE: ch is : 3, 5046494851
NOTICE: iBigArr is: {504850484548564550,533250495850535848,5046494851}
ERROR: integer out of range
CONTEXT: PL/pgSQL function hashids.encode_list(bigint[],text,integer,text,boolean) line 48 at assignment
PL/pgSQL function hashids.encode_list(bigint[],text,integer) line 10 at RETURN