I'm trying insert data in table using this query
INSERT INTO table (
url,
v_count,
v_date)
SELECT
url,
v_count,
v_date FROM json_populate_recorset(null::record,
'[{"url_site":"test.com","visit_count":1,"visit_date":"2022-08-31"},
{"url_site":"dev.com","visit_count":2,"visit_date":"2022-08-31"}]'::json)
AS ("url" varchar(700), "v_count" integer, "v_date" date)
And I'm getting this error: null value in column "v_date" of relation table violates not null constraint
Since my json could be hundreds of entries at some times, how should I send the date in my json ? There is another (efficient) way to insert this data in the table ?
Edit: in postico 1.5.20 my example above works as long as I have the json key named the same as the table columns, how can I reference differents names in my json keys?
json_populate_recordsetwithrecordas the type looks like a bad idea, since it'll basically ignore the property namesjson_array_elements(…), thenel->>'url_site',(el->> 'visit_count')::int,(el->>'visit_date')::date.