porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.09k stars 259 forks source link

Multiple update with array casting issue #741

Open dekdevy opened 8 months ago

dekdevy commented 8 months ago

Hey, im trying to update multiple rows with a real[] column.

My approach is this:

const data = [[123, [1.2,3.4,5.6]], ... ]

UPDATE mytable as t
  SET myreal = (v.myreal)::real[]
  FROM (VALUES ${sql(data)}) AS v(id, myreal)
  WHERE t.id = (v.id)::int 

This throws a PG error: malformed array literal: "1.2,3.4,5.6". This leads me to believe that I cannot hand an array in like this as it is being cast to a string and sent directly. I found a workaround using const data = [[123, '{'+[1.2,3.4,5.6].join(',')+'}'], ... ].

Am I doing something wrong?