postgresql migrating JSON to JSONB

Boaz picture Boaz · Jan 28, 2015 · Viewed 21.9k times · Source

In postgresql 9.4 the new JSONB was incorporated.

On a live DB in postgresql 9.3 I have a JSON column.

I want to migrate it to JSONB.

Assuming I migrated the DB first to 9.4 (using pg_upgrade). What do I do next?

Answer

Marth picture Marth · Jan 28, 2015
ALTER TABLE table_with_json
  ALTER COLUMN my_json
  SET DATA TYPE jsonb
  USING my_json::jsonb;