37
psql --version
psql (PostgreSQL) 9.4.1

rails -v
Rails 4.2.0

I added a jsonb column through migration like that

class AddPreferencesToUsers < ActiveRecord::Migration
  def change
    add_column :users, :preferences, :jsonb, null: false, default: '{}'
    add_index :users, :preferences, using: :gin
  end
end

I get this error :

PG::UndefinedObject: ERROR:  type "jsonb" does not exist
LINE 1: SELECT 'jsonb'::regtype::oid

any help ?

medBouzid
  • 7,484
  • 10
  • 56
  • 86
  • i saw this problem the other day too, seems there hasn't been any solution to this. could you try upgrading to 4.2.1 or downgrading your rails – argentum47 Apr 01 '15 at 15:10
  • @argentum47 I think it's my fault, I will fix it and post the answer. thank you. – medBouzid Apr 01 '15 at 18:07

1 Answers1

71

After looking around I discovered that my postgresql version is not 9.4 by running the right command

postgres=# SHOW SERVER_VERSION;
server_version 
----------------
9.1

So I had simply to upgrade my postgresql to 9.4.

By the way I followed this article to do the upgrading which I found very handy.

Now :

postgres=# SHOW SERVER_VERSION;
 server_version 
----------------
 9.4.1

Hope this help someone in the same situation.

medBouzid
  • 7,484
  • 10
  • 56
  • 86
  • 1
    Correct. Upgrading postgresql version helps. This [other upgrading guide](https://medium.com/@tk512/upgrading-postgresql-from-9-3-to-9-4-on-ubuntu-14-04-lts-2b4ddcd26535) works as well. – Francisco Quintero Aug 21 '17 at 00:07
  • 2
    The guide is for most debian systems - but there is a bit more that needs to be done for Ubuntu 14.04 (which does not have the postgres-9.4 package/repository). For older versions of Ubuntu, search on askubuntu.com as there is a plethora of solutions there. – Todd Sep 29 '17 at 15:33
  • for anyone else coming across this, I used [this article](https://medium.com/@tk512/upgrading-postgresql-from-9-4-to-9-5-on-ubuntu-14-04-lts-dfd93773d4a5) and successfully upgraded directly from Postgres 9.3 to 10.5 on Ubuntu 14.04. The article is for 9.4 -> 9.5 but works well for 9.3 -> 10.5 ! – FireDragon Aug 18 '18 at 06:22
  • [Here](https://askubuntu.com/a/633923/428475) are the instructions which guides in installing postgres-9.4 on Ubuntu 14.04 – Jignesh Gohel Aug 30 '18 at 09:55