Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong result when encoding bigger numbers #14

Closed
gpip opened this issue Jan 12, 2018 · 4 comments
Closed

Wrong result when encoding bigger numbers #14

gpip opened this issue Jan 12, 2018 · 4 comments

Comments

@gpip
Copy link

gpip commented Jan 12, 2018

Hey, I was just trying this extension with Postgres 10 and found something odd:

select id_encode(1981515714898, 'salt1', 6, 'ABCDEFGHJKLMNPRSTVXYZ');
 id_encode  
------------
 XDMNVNJPBP
(1 row)


select id_decode('XDMNVNJPBP', 'salt1', 6, 'ABCDEFGHJKLMNPRSTVXYZ');
  id_decode   
--------------
 {1535791442}
(1 row)

The python hashid module returns 'XXAJGNGVJEBX' (and not 'XDMNVNJPBP'), and if I pass that value to id_decode I get back the expected id 1981515714898

@gpip
Copy link
Author

gpip commented Jan 12, 2018

I see the code is using PG_GETARG_INT32 for the id, shouldn't that be at least INT64 instead?

@iCyberon
Copy link
Owner

@gpip Does this work for you?

select id_encode(ARRAY[1981515714898], 'salt1', 6, 'ABCDEFGHJKLMNPRSTVXYZ');
select id_decode('XXAJGNGVJEBX', 'salt1', 6, 'ABCDEFGHJKLMNPRSTVXYZ');

It should work, I'll fix the issue.

iCyberon added a commit that referenced this issue Jan 12, 2018
@iCyberon
Copy link
Owner

@gpip Just pushed v1.2.1, should work with BIGINT. Let me know if you encounter other issues.

@gpip
Copy link
Author

gpip commented Jan 12, 2018

Thank you for the fix! Earlier I recompiled it with INT64, haven't tried using ARRAY but looks fine to me

@gpip gpip closed this as completed Jan 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants