I have the following table:
┌────────────────┬─────────────────────────────┬───────────┬──────────┬──────────────────────────────────────────────────────────────────┐
│ Column │ Type │ Collation │ Nullable │ Default │
├────────────────┼─────────────────────────────┼───────────┼──────────┼──────────────────────────────────────────────────────────────────┤
│ id │ bigint │ │ not null │ nextval('"HistoricalDataAggregatorWorkOrders_id_seq"'::regclass) ││
│ inputTimeRange │ tstzrange │ │ not null │ │
│ outputTags │ tag[] │ │ not null │ │
└────────────────┴─────────────────────────────┴───────────┴──────────┴──────────────────────────────────────────────────────────────────┘
I want to bulk insert a bunch of rows into it in one parameterized query. I thought I’d be able to do it the usual way with unnest
:
INSERT INTO "HistoricalDataAggregatorWorkOrders"
("inputTimeRange", "outputTags")
SELECT * from unnest($1::tstzrange[], $2::tag[][])
RETURNING id;
But unfortunately, unnest
doesn’t work the way I want (it flattens the array).
I gather from /a/8142998/200224 that there’s no builtin unnest-one-level function.
Is there really no simple way to bulk insert with a parameterized query when one column is an array type? Seems like a missing feature…