sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.48k stars 805 forks source link

Code created with duplicated fields #2429

Open leobrines opened 1 year ago

leobrines commented 1 year ago

Version

Other

What happened?

Hi guys!

It generates an invalid go struct when there are duplicated fields at schema. Go compiler generates a redeclared field error.

type Tournament struct {
    ID     string
    Status sql.NullString
    Status sql.NullString
}

Using sqlc version 1.19.0

Relevant log output

No response

Database schema

CREATE TABLE tournaments (
    id VARCHAR(255) NOT NULL,
    status VARCHAR(255),
    status VARCHAR(255)
);

SQL queries

-- name: FindTournamentByID :one
SELECT *
FROM tournaments
WHERE id = ?;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "sqlite",
      "name": "sqlite",
      "schema": "query.sql",
      "queries": "query.sql",
      "engine": "sqlite",
      "emit_json_tags": false,
      "emit_prepared_queries": true,
      "emit_interface": true
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/9dadfd2d3b03f88c36209c864a83167e464cb327d8cb5a31aea62242b5b5fb58

What operating system are you using?

Windows

What database engines are you using?

SQLite

What type of code are you generating?

Go

orisano commented 1 year ago

I don't think SQLite allows duplicate columns to be defined in CREATE TABLE, what behavior do you expect?

leobrines commented 1 year ago

It is expected it does not generate code that cannot compile