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

Generate fails for UPDATE ... FROM (...) with subquery #3341

Open
AntonOcean opened this issue Apr 16, 2024 · 1 comment
Open

Generate fails for UPDATE ... FROM (...) with subquery #3341

AntonOcean opened this issue Apr 16, 2024 · 1 comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@AntonOcean
Copy link

Version

1.25.0

What happened?

UPDATE statement with FROM subquery does not generate!

Relevant log output

sqlc generate failed.
# package 
query.sql:23:14: column "id" does not exist

Database schema

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

-- name: UpdateAuthor :exec
UPDATE authors SET name=subquery.name, bio=subquery.bio
FROM (SELECT id, name, bio
        FROM unnest($1::authors[])) AS subquery
WHERE authors.id = subquery.id;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "postgresql",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/146482ad583aa6e0a2980b0d0feb5e6c42628406a3f44b1eadfd925278b341e0

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@AntonOcean AntonOcean added bug Something isn't working triage New issues that hasn't been reviewed labels Apr 16, 2024
@AntonOcean AntonOcean changed the title Generate fails for UPDATE ... FROM (...) subquery Generate fails for UPDATE ... FROM (...) with subquery Apr 16, 2024
@AntonOcean
Copy link
Author

Also this is why i can't use "SELECT * FROM unnest(...)" in my case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed
Projects
None yet
Development

No branches or pull requests

1 participant