Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query is not inferred correctly when doing multiple update, and a value is an array. #811

Open
raprocks opened this issue Feb 21, 2024 · 1 comment

Comments

@raprocks
Copy link

raprocks commented Feb 21, 2024

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?

@raprocks
Copy link
Author

raprocks commented Feb 21, 2024

i fixed it for now by using insert ... ON CONFLICT DO UPDATE SET keywords = EXCLUDED.keywords

still would like to know what is wrong,.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant