Syntax Error on Dynamic multiple updates in one query giving
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
Anyone can help finding the issue? Getting syntax error on this query:
exports.updateMatches = async ({ payload: { matches } }) => {
const formattedMatches = objArrToArr(matches);
const cols = Object.keys(matches[0]);
const colsWOId = cols
.filter((item) => item !== "id")
.map((item) => camelToSnake(item));
return await sql`
update matches
set ${colsWOId.map((col) => `${sql(col)} = excluded.${sql(col)}`).join(", ")}
from (values ${sql(formattedMatches)}) as excluded(${cols.join(", ")})
where matches.id = (excluded.id):: int
returning *;`;
};
tried to follow the sql format from official documentation:
const users = [
[1, 'John', 34],
[2, 'Jane', 27],
]
await sql`
update users set name = update_data.name, age = (update_data.age)::int
from (values ${sql(users)}) as update_data (id, name, age)
where users.id = (update_data.id)::int
returning users.id, users.name, users.age
`
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
Start with the updateMatches function and compare its dynamic sql template with the official multiple-row UPDATE example included in the issue. Inspect the SQL generated from colsWOId and formattedMatches; done means identifying the syntax error and confirming that the matches rows update successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100