I have a domain that represents an array of integers, created with CREATE DOMAIN x AS integer[]. I have a field in a table that has type x[], i.e. an array of arrays of integers. I have done this (as opposed to integer[][]) to allow mixed-length arrays (see this answer).
Inserting the expression {{1, 2}, {3, 4, 5}} would look like:
INSERT INTO table (column) VALUES (ARRAY[ARRAY[1, 2]::x, ARRAY[3, 4, 5]::x])
Without the domain (i.e. when column is of type integer[][]), I can use pg-promise to insert the multidimensional array above:
const arr = [[1, 2], [3, 4, 5]];
await db.query('INSERT INTO table (column) VALUES ($1)', arr);
And select it:
const result = await db.query('SELECT column FROM table');
result[0].column[1][2] // => 5
But this of course has the limitation mentioned at the start, that SQL (or at least Postgres) doesn't allow multidimensional arrays with different length rows.
Selecting a column of type x[] with pg-promise in the same way as above results in a string, and inserting a raw array (as above) understandably throws an error ("column is of type x[] but expression is of type integer[]"). Adding ::x[] (i.e. INSERT INTO table (column) VALUES ($1::x[]) also throws an error, "cannot cast type integer to x", which also make sense.
So my question is, what is the best way to select and insert fields that are arrays of a domain with pg-promise? I looked at custom type formatting, but I'm not sure that it would work for selecting. Thanks!