Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails and jsonb type "jsonb" does not exist

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 ?

like image 206
medBouzid Avatar asked Apr 01 '15 14:04

medBouzid


People also ask

What is Jsonb data type?

The JSONB data type stores JSON (JavaScript Object Notation) data as a binary representation of the JSONB value, which eliminates whitespace, duplicate keys, and key ordering. JSONB supports GIN indexes.

What is Jsonb in Postgres?

JSONB stands for “JSON Binary” or “JSON better” depending on whom you ask. It is a decomposed binary format to store JSON. JSONB supports indexing the JSON data, and is very efficient at parsing and querying the JSON data. In most cases, when you work with JSON in PostgreSQL, you should be using JSONB.

Should I use JSON or Jsonb?

In general, most applications should prefer to store JSON data as jsonb , unless there are quite specialized needs, such as legacy assumptions about ordering of object keys. RFC 7159 specifies that JSON strings should be encoded in UTF8.

Does hibernate support Jsonb?

Hibernate dialectHibernate's PostgreSQL dialect does not support the JSONB datatype, and you need to register it.


1 Answers

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.

like image 133
medBouzid Avatar answered Oct 09 '22 03:10

medBouzid