JSON Data Type Support for PostgreSQL

Hello,

I am using yii2 with PostgreSQL 9.4 version. In my database schema, my chain table looks like:

CREATE TABLE chain (

id BIGINT NOT NULL DEFAULT nextval(‘chain_id_seq’) PRIMARY KEY,

name VARCHAR(80) NOT NULL UNIQUE,

contacts JSONB, – contacts: [array { name, number, email }]

notes TEXT,

created_at INT,

updated_at INT

);

I have Chain class extending ActiveRecord, with properties as follow:

  • @property integer $id

  • @property string $name

  • @property string $data

[b] * @property string $contacts

[/b] * @property string $notes

  • @property integer $created_at

  • @property integer $updated_at

My question is if I want to use array php type for $contacts which is automatically converted into JSON string while storing into db, and back to array when fetch from db.

How can I do that?