Search code examples
sqlrubypostgresqlheroku

How to add intarray extension to PostgreSQL on Heroku


The app I have is using intarray extension of the PostgreSQL.

Unfortunately it doesn't seem to be available according to the docs and the command line:

> echo 'show extwlist.extensions' | heroku pg:psql
                                                                                extwlist.extensions                                                                                 
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 btree_gist,chkpass,cube,dblink,dict_int,dict_xsyn,earthdistance,fuzzystrmatch,hstore,isn,ltree,pg_trgm,pgcrypto,pgrowlocks,pgstattuple,plpgsql,unaccent,uuid-ossp,citext,tablefunc
(1 row)

Also:

> heroku pg:psql
psql (9.1.5, server 9.1.6)
SSL connection
Type "help" for help.

=> CREATE EXTENSION intarray;
WARNING:  extension "intarray" is not whitelisted
CREATE EXTENSION

So does it mean I can't use Heroku or there IS a way to add intarray extension (using idx function for example).

Thanks.


Solution

  • Have to answer my own question just to provide a little bit more details.

    The intarray was used for extracting path information from columns containing strings like 123/312/56/9863. That was stored (poorly) as string instead of an array in the first place.

    The reason we needed intarray is because we it had the idx function.

    What was happening is this:

    • convert string to an array
    • find the given number using the idx
    • return the next number in sequence.

    All that was done as a temporary measure. But since heroku couldn't support idx the only way to use it was by adding a custom function. But instead we converted the queries and data structure to to use ltree and its index function.

    Apart from not needing a dependency on idx (but introducing another dependency on ltree), we also improved the performance of the queries by a factor of x200.