Upgrade PostgreSQL JSON column to JSONB?

srlm picture srlm · Jan 21, 2015 · Viewed 7.9k times · Source

After upgrading to PostgreSQL 9.4, how do I convert all my JSON columns into JSONB columns?

I don't mind losing any duplicate keys and whitespace.

Answer

Tometzky picture Tometzky · Jan 21, 2015
ALTER TABLE t ALTER COLUMN j TYPE jsonb USING j::text::jsonb;