Skip to content

Array indexes not correctly handled on update set #1532

Closed

Description

@stephanievance29

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

Activity

  1. kyleconroy commented on Sep 22, 2023

    @kyleconroy
    Collaborator
  2. orisano commented on Sep 23, 2023

    @orisano
    Contributor
  3. andrewmbenton commented on Oct 16, 2023

    @andrewmbenton
    Member

    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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions