I am trying to pass the Postgres 65535 parameter limit by utilizing "unnest". It works like a charm for every type except for arrays. Working example:
(db-dsl/exec-sql
"INSERT INTO test (num,dob) (SELECT * FROM UNNEST (?::bigint[], ?::date[])) RETURNING *"
(into-array [1 2])
(into-array ["01.01.2010" "01.01.1990"]))
But I can't pass an array type:
(db-dsl/exec-sql
"INSERT INTO test (nums,dob) (SELECT * FROM UNNEST (?::bigint[][], ?::date[])) RETURNING *"
(into-array [(into-array [1 2]) (into-array [1 2])])
(into-array ["01.01.2010" "01.01.1990"]))
Have you tried to achieve something like this?Table example:
CREATE TABLE test (
oid BIGSERIAL PRIMARY KEY,
num BIGINT,
nums BIGINT[],
dob TIMESTAMP);If you're using next.jdbc under the hood, there are "type hint" functions that may help...
https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.865/api/next.jdbc.types
Thank you! I tried:
(db-dsl/exec-sql
"INSERT INTO test (nums) (SELECT * FROM UNNEST (?::bigint[][])) RETURNING *"
(jdbc-types/as-array (into-array [(into-array [1 2]) (into-array [1 2])])))
The result is the same as before:
ERROR: column \"nums\" is of type bigint[] but expression is of type bigint\n Hint: You will need to rewrite or cast the expression.\n Position: 33
If there is a type hint like as-array-of-arrays 🙂Sounds like it is UNNESTing things more than one level?
(I don't use PG so I'm not familiar with how that is supposed to work)
Found a way with unnesting separately. It can pass 65k rows, don't know yet whether performance could suffer from this approach (compared to the previous version).
(db-dsl/exec-sql
"INSERT INTO test (nums,dob)
(SELECT unnest_2d_1d(a1), unnest(a2) FROM (SELECT ?::bigint[][], ?::date[]) t(a1,a2))
RETURNING *"
(into-array [(into-array [1 2]) (into-array [1 2])])
(into-array ["01.01.2010" "01.01.1990"]))
Need a procedure to reduce an array dimension, like I used unnest_2d_1d
Can be found here: https://stackoverflow.com/questions/8137112/unnest-array-by-one-level