Open
Description
I was attempting to verify I could do a merge query with 'postgres'
const insertedBabies = await sql`
MERGE INTO baby.babies b
USING (VALUES ${sql(babies)}) as s (baby_id, birthdate, name)
ON b.id = s.baby_id::int
WHEN NOT MATCHED THEN
INSERT (name, birthdate)
VALUES (s.name, s.birthdate)
`
and tried several variations, and came across another issue, I can't merely cast birthdate like this s (baby_id, birthdate::date, name)
.
Debug shows something like this
MERGE INTO baby.babies b
USING (VALUES ($1,$2,$3)) as s (baby_id, birthdate, name)
ON b.id = s.baby_id::int
WHEN NOT MATCHED THEN
INSERT (name, birthdate)
VALUES (s.name, s.birthdate)
[
{ baby_id: 68, birthdate: null, name: 'w1', role: 'admin' },
{ name: 'w2', birthdate: 2023-04-09T21:41:00.000Z },
{ name: 'w3', birthdate: 2023-04-09T21:41:00.000Z }
] [ 0, 0, 0 ]
So I guess two issues
- How do you do multiple dynamic merge in postgres
- How do you cast a certain group of columns doing an operation like this? Which I think relates to this issue Multiple updates in one query -> not working "operator does not exist: integer = text" #539