sqlc-dev/sqlc

Postgresql column ambiguity with using clause

prog8 opened this issue · 0 comments

prog8 commented

Version

1.27.0

What happened?

Postgres docs says USING clause makes redundant column suppressions.

Furthermore, the output of JOIN USING suppresses redundant columns: there is no need to print both of the matched columns, since they must have equal values. While JOIN ON produces all columns from T1 followed by all columns from T2, JOIN USING produces one output column for each of the listed column pairs (in the listed order), followed by any remaining columns from T1, followed by any remaining columns from

Unfortunately sqlc finds redundant column name ambiguous

Relevant log output

column reference "fk" is ambiguous

Database schema

create table t1 (
        fk integer not null unique
);
create table t2 (
        fk integer not null references t1(fk)
);

SQL queries

-- name: SelectJoinUsing :many
select fk, sum(t2.fk) from t1 join t2 using (fk) group by fk;

Configuration

version: "2"
sql:
  - engine: "postgresql"
    schema: "schema.sql"
    queries: "query.sql"
    gen:
      go:
        package: "querytest"
        out: "go"
        sql_package: "pgx/v5"

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