Skip to content

fix(compiler): Set RV for TargetList items on updates #1252

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

Merged
merged 3 commits into from
Nov 6, 2021

Conversation

andreasgangso
Copy link
Contributor

Hi, thank you for this library!
I stumbled upon a bug with updates not working on update queries with multiple tables. It gave an error column does not exist which was because ref.rv was nil.
This PR fixes this by looping through the TargetList and setting the ref.rv from the Relation, similarly to what inserts already do. Here's the relevant AST:

   Relation: (*ast.RangeVar)(0xc000ac2ab0)({
    Catalogname: (*string)(<nil>),
    Schemaname: (*string)(<nil>),
    Relname: (*string)(0xc000aa3b40)((len=5) "media"),
    Inh: (bool) true,
    Relpersistence: (uint8) 112,
    Alias: (*ast.Alias)(0xc000aa3b60)({
     Aliasname: (*string)(0xc000aa3b50)((len=2) "m1"),
     Colnames: (*ast.List)(0xc000aa75f0)({
      Items: ([]ast.Node) <nil>
     })
    }),
    Location: (int) 1469
   }),
   TargetList: (*ast.List)(0xc000aa7608)({
    Items: ([]ast.Node) (len=1 cap=1) {
     (*ast.ResTarget)(0xc000ac2ae0)({
      Name: (*string)(0xc000aa3b70)((len=9) "agerating"),
      Indirection: (*ast.List)(0xc000aa7620)({
       Items: ([]ast.Node) <nil>
      }),
      Val: (*ast.ParamRef)(0xc000527f98)({
       Number: (int) 5,
       Location: (int) 1696,
       Dollar: (bool) true
      }),
      Location: (int) 1684
     })
    }
   }),

@andreasgangso
Copy link
Contributor Author

Sure, but it will take a few days before I have time

Copy link
Collaborator

@kyleconroy kyleconroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add at least one test case? There are many examples in the internal/endtoend/testdata directory.

@andreasgangso
Copy link
Contributor Author

andreasgangso commented Nov 1, 2021 via email

@kyleconroy
Copy link
Collaborator

@andreasgan Sorry for the second message! I realized that I hadn't posted the comment as a review. No rush, seriously.

@andreasgangso
Copy link
Contributor Author

@andreasgan Sorry for the second message! I realized that I hadn't posted the comment as a review. No rush, seriously.

No worries. Tests added now.

@kyleconroy kyleconroy merged commit 6b5f4d6 into sqlc-dev:main Nov 6, 2021
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

Successfully merging this pull request may close these issues.

2 participants