I have a table with type varchar[]
Field Name | Field Type |
---|---|
id | int |
data | varchar[][] |
insert_date | timestamps |
I have a data json object
{
{
name : "Mr. A",
class:
{
class_id: 1,
exam: 95,
},
{
class_id: 2,
exam: 78,
}
},
{
name : "Mr. B",
class:
{
class_id: 1,
exam: 87,
},
{
class_id: 2,
exam: 87,
}
}
}
how do i insert the data into 1 row?
You should be use jsonb
to store JSON data in your table.
CREATE TABLE customer {
contact JSONB
}
Example(Object):- Insert Object JSON Value
Insert into customer(contact )
Values('{ "phones":[ {"type": "mobile", "phone": "001001"} , {"type": "fix", "phone": "002002"} ] }')
Example(Array):- Insert array JSON Value
Insert into customer(contact )
Values('[ {"type": "mobile", "phone": "001001"} , {"type": "fix", "phone": "002002"} ]')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.