postgres change jsonb[] to jsonb

前端 未结 2 1105

I use postgres9.4, and there exists relation \"Patients\" has column \"contact\" with type jsonb[], how to transfer type jsonb[] to

2条回答
  •  隐瞒了意图╮
    2020-12-20 10:20

    As of 9.5 version, to preserve the data and keep the data in json as array this would work much better.

    ALTER TABLE "Patients"  ALTER COLUMN "contact" DROP DEFAULT
    ALTER TABLE "Patients"  ALTER COLUMN "contact" TYPE jsonb USING to_json(contact)
    ALTER TABLE "Patients"  ALTER COLUMN "contact" SET DEFAULT '[]'
    

提交回复
热议问题