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

Array indexes not correctly handled on update set #1532

Closed
stephanievance29 opened this issue Apr 5, 2022 · 4 comments · Fixed by #2864
Closed

Array indexes not correctly handled on update set #1532

stephanievance29 opened this issue Apr 5, 2022 · 4 comments · Fixed by #2864

Comments

@stephanievance29
Copy link

stephanievance29 commented Apr 5, 2022

I have a SQL query in my project that is attempting to update an array at a specific index but it is not being handled correctly. I was able to replicate this issue in a separate project and pasted the sample query below.

-- name: UpdateRow :one
update temp
set places[$1] = $2
where id=$3
RETURNING *;

The generated code treats places[$1] as an array input parameter instead of accepting $1 as the index of the places column.

Playground

https://play.sqlc.dev/p/a7c1a274a647d8c2452f4bc9cd93f8a76bf09c43745ea428859433edec18aaa1

@kyleconroy
Copy link
Collaborator

I was going to suggest using a type cast, but that also doesn't work

https://play.sqlc.dev/p/31c401f520c8cc7166e02d8b8a3cb71a78a6dc89902877a5de45f83aca7ddc72

@kyleconroy kyleconroy added bug Something isn't working analyzer labels Sep 22, 2023
@orisano
Copy link
Contributor

orisano commented Sep 23, 2023

This works correctly.
https://play.sqlc.dev/p/d472b30aa6c2fac886b797341eaa84343bd8676f825a5a597a64acbaa2dcd33d

@andrewmbenton
Copy link
Collaborator

andrewmbenton commented Oct 16, 2023

This works correctly. https://play.sqlc.dev/p/d472b30aa6c2fac886b797341eaa84343bd8676f825a5a597a64acbaa2dcd33d

I'm not sure that's correct though. The array index has the correct type but the assignment to the array element should be a string I think right? Not an array of strings?

I think casting @name::text will work though: https://play.sqlc.dev/p/bad6f4c76953c419bcdb391b04498e81c3b39f69896ee28fd110d3803448ebf4

kyleconroy added a commit that referenced this issue Oct 18, 2023
* fix(compiler): Pull in array information from analyzer
Fixes #1532
* test(analyzer): Add testcase for #1574
* test: Added test for #1634
* test: Add test case for #1646
* test: Add test for #1714
* Fixes #1912
* test: Add case for #1916
* test: Add two test cases
#1917
#1545
* test: Add case for #1979
* test: Add case for #1990
@kyleconroy
Copy link
Collaborator

Fixed in v1.23.0. You can see an example here: https://play.sqlc.dev/p/3807c7209ed1e1c09fd5520223590e0ade7d7dfdfc49996ad57dbd818eb9f27a

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

Successfully merging a pull request may close this issue.

4 participants