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

Ambiguous column checking creates false positives #3325

Open
ncabatoff opened this issue Apr 5, 2024 · 0 comments
Open

Ambiguous column checking creates false positives #3325

ncabatoff opened this issue Apr 5, 2024 · 0 comments
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@ncabatoff
Copy link

ncabatoff commented Apr 5, 2024

Version

1.25.0

What happened?

Here's an example: https://play.sqlc.dev/p/f32a811caf892026c11495a0059cc4eb041ba647e746f47316873f7bc85bd3bd

The CreateTitle query INSERT INTO titles (id, name, author_id) VALUES ($1, $2, (SELECT author_id FROM authors WHERE name = $3)); is flagged:

query.sql:22:95: column reference "name" is ambiguous

I don't believe it's ambiguous in the context of the sub-select.

Note that I see this problem with CTEs as well, I can provide an example if needed.

Relevant log output

query.sql:22:95: column reference "name" is ambiguous

Database schema

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

CREATE TABLE titles (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  author_id BIGINT NOT NULL ,
  CONSTRAINT fk_authors FOREIGN KEY(author_id) REFERENCES authors(id)
);

SQL queries

INSERT INTO titles (id, name, author_id) VALUES ($1, $2, (SELECT author_id FROM authors WHERE name = $3));

Configuration

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

Playground URL

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

What operating system are you using?

Linux, macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@ncabatoff ncabatoff added bug Something isn't working triage New issues that hasn't been reviewed labels Apr 5, 2024
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