iCyberon / pg_hashids

Short unique id generator for PostgreSQL, using hashids
MIT License
288 stars 25 forks source link

error: function id_encode(bigint, unknown, integer, unknown) does not exist #7

Closed cashweaver-zz closed 7 years ago

cashweaver-zz commented 7 years ago

Just pushed an app up to production and started getting this error:

error: function id_encode(bigint, unknown, integer, unknown) does not exist

I'm invoking id_encode like:

CREATE OR REPLACE FUNCTION fourchar_short_id(i BIGINT)
RETURNS TEXT AS $$
DECLARE key TEXT;
BEGIN
  key := id_encode(i, 'mysalt', 4, 'abcdefghkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789-_');
  key := substring(key from 0 for 5);
  RETURN key;
END;
$$ language 'plpgsql';

Haven't seen it in local development at all. I'm trying to track down the mistake I've made and will update this issue for future reference.

iCyberon commented 7 years ago

@cashweaver What's the result of this query?

SELECT default_version, installed_version 
FROM pg_available_extensions 
WHERE name = 'pg_hashids';
cashweaver-zz commented 7 years ago

Additional errors (for future searchability):

SELECT * FROM id_encode(CAST (14 as BIGINT), 'mysalt', 4, 'abcdefghkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789-_');
ERROR:  function id_encode(bigint, unknown, integer, unknown) does not exist
LINE 1: SELECT * FROM id_encode(CAST (14 as BIGINT), 'mysalt...
SELECT * FROM id_encode(CAST (14 as BIGINT), CAST ('mysalt' as text), 4, CAST ('abcdefghkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789-_' as text));
ERROR:  function id_encode(bigint, text, integer, text) does not exist
LINE 1: SELECT * FROM id_encode(CAST (14 as BIGINT), CAST ('mysalt...
cashweaver-zz commented 7 years ago

Thanks for the sanity-check!

SELECT default_version, installed_version 
FROM pg_available_extensions 
WHERE name = 'pg_hashids';

 default_version | installed_version 
-----------------+-------------------
 1.2             | 
(1 row)

Turns out I had my terminals mixed up and was running the installation commands on my local dev environment. I had never run ALTER EXTENSION pg_hashids UPDATE; on my prod server.

ALTER EXTENSION pg_hashids UPDATE;
ALTER EXTENSION

SELECT default_version, installed_version 
FROM pg_available_extensions 
WHERE name = 'pg_hashids';

 default_version | installed_version 
-----------------+-------------------
 1.2             | 1.2
(1 row)

SELECT * FROM id_encode(CAST (14 as BIGINT), 'mysalt', 4, 'abcdefghkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789-_');
 id_encode 
-----------
 8WQ6
(1 row)

Working perfectly now!