const arryTest = [
{
name: 'name1',
commens: 'commens1',
like: 2,
date: '01,01,2022'
},
{
name: 'name2',
commens: 'commens2',
like: 25,
date: '01,01,2022'
},
{
name: 'name3',
commens: 'commens3',
like: 35,
date: '01,01,2022'
},
]
create table comments (
"name" varchar,
"commens" varchar,
"like" int,
"date" timestamp
);
insert into comments
select (json_populate_record(null::comments, value)).* from json_array_elements('[
{
"name": "name1",
"commens": "commens1",
"like": 2,
"date": "2022-01-01"
},{
"name": "name2",
"commens": "commens2",
"like": 2,
"date": "2022-01-01"
},{
"name": "name3",
"commens": "commens3",
"like": 2,
"date": "2022-01-01"
}
]');
select * from comments;