Skip to content

Column reference is ambiguous in subquery #4251

@Boris-creator

Description

@Boris-creator

Version

1.30.0

What happened?

Cannot compile a correct query, got error column reference "id" is ambiguous, the problem column is in a subquery.

Relevant log output

column reference "id" is ambiguous

Database schema

CREATE TABLE IF NOT EXISTS t1 (
    id  UUID PRIMARY KEY
);

CREATE TABLE IF NOT EXISTS t2 (
    id    UUID,
    t1_id UUID  REFERENCES t1(id) ON DELETE CASCADE
);

SQL queries

-- name: GetT1 :many
SELECT * FROM t1
WHERE id IN (
    SELECT t1_id
    FROM t2
    WHERE id = $1
);

Configuration

version: "2"
sql:
  - engine: "postgresql"
    schema: "../migrations"
    queries: "internal/db/query/example"
    gen:
      go:
        package: "query"
        out: "internal/db/query/example"
        sql_package: "pgx/v5"
        emit_sql_as_comment: true

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

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