query is not inferred correctly when doing multiple update, and a value is an array.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
please let me know if i am doing something wrong lol. i am trying to update multiple records in a table that has one of the columns as an varchar[] and other columns are of type int and text.
example input:
[{"project_id":83,"keyword":["adasda"],"type":"APARTMENT_CONTAINS"},{"project_id":83,"keyword":[],"type":"COUNTERPARTY_CONTAINS"},83]
typescript code, updateRes.id is a number equivalent to project_id as seen in params below in debug info:
const _keywords_insert_res = await sql<{ id: number }[]>`
UPDATE public.keywords
SET
${sql(keywords_to_insert)}
WHERE project_id = ${updateRes.id}
`;
generated query:
UPDATE public.keywords
SET
"0"=$1,"1"=$2
WHERE project_id = $3
other debug info:
Params: [{"project_id":83,"keyword":["adasda"],"type":"APARTMENT_CONTAINS"},{"project_id":83,"keyword":[],"type":"COUNTERPARTY_CONTAINS"},83]
Param Types: [0,0,0]
Why is the generated query taking column names as 0 and 1 when i have passed in the array of object, i.e, instead of project_id or keyword or type. i might be surely doing something wrong but would be great to know if this is not an issue and it is just me being dumb :P is this just a syntax error on my end for postgres.js or postgresdb?
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 UPDATE using the shown TypeScript template and the sql(keywords_to_insert) interpolation, comparing the generated column names and parameter types with the supplied objects. Trace how this interpolation handles an array of objects; done means determining whether the result is expected syntax or a postgres.js inference bug.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100