Multiple update with array casting issue
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the shown UPDATE against PostgreSQL with the provided data, then trace how Postgres.js serializes arrays in the VALUES expression. Done means determining whether JavaScript arrays can be passed directly for real[] columns and adding regression coverage if the behavior is a bug; the issue names no repository files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgresql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100