iCyberon / pg_hashids

Short unique id generator for PostgreSQL, using hashids
MIT License
280 stars 24 forks source link

Simpler way to link to a query: {decoded_value} #4

Closed xavicolomer closed 7 years ago

xavicolomer commented 7 years ago

I found way link the hashid to a query but it looks complicated. I want to get rid of the {} returned by id_decode.

Is there a simpler way rather than:

SELECT * FROM mytable,
       (SELECT CAST(translate(id_decode('my_id', 'my_salt', 10)::text, '{}', '') as int4) as id) as hash
                                  WHERE mytable.id = hash.id;

I tried comparing the value directly:

ERROR: operator does not exist: integer = bigint[]

And CAST the result as int4 :

CAST(id_decode('my_id', 'my_salt', 10)::text, '{}', '') as int4)

iCyberon commented 7 years ago

@xavicolomer You can use id_decode_once which returns BIGINT. I will update the readme soon :)