SELECT UNNEST(ARRAY[1,2,3,4])
While executing the above query I got the error like this:
ERROR: function unnest(integer[]) does not exist in postgresql.
I am using PostgreSQL 8.3 and I have installed the _int.sql
package in my db for integer array operation.
How to resolve this error?
unnest()
is not part of the moduleintarray
, but of standard PostgreSQL. However, you need version 8.4 or later for that.So you can resolve this by upgrading to a more recent version, preferably the current version 9.1. See the versioning policy of the PostgreSQL project.
If you should be using Heroku's shared database, which currently uses version 8.3, they are looking into upgrading, too. Heroku Labs already offers 9.1.
As @Abdul commented, you can implement a poor man's
unnest()
in versions before PostgreSQL 8.4 yourself:However, be aware that this only works for one-dimensional arrays. (As opposed to PostgreSQL's
unnest()
which takes arrays with multiple dimensions):You could implement more functions for n-dimensional arrays:
Call:
You could also write a PL/pgSQL function that deals with multiple dimensions ...