Skip to content

Rename struct property name when using sqlc.embed in multiple joins from same table #3177

@lcnlvrz

Description

@lcnlvrz

Version

1.25.0

What happened?

I just need to perform a query that joins multiple rows from same table and i expect sqlc to take alias from query when build final go structs

In current version when you join multiple times from same table, the final struct looks something like:

struct QueryOutput {
TableRow1  Table
TableRow2 Table
}

Relevant log output

No response

Database schema

CREATE TABLE tracks(
    id SERIAL PRIMARY KEY,
    driver_id INTEGER NOT NULL REFERENCES persons(id),
    recipient_id INTEGER NOT NULL REFERENCES persons(id)
);


CREATE TABLE persons(
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255),
    phone VARCHAR(255) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

SQL queries

SELECT * FROM tracks
LEFT JOIN persons as driver ON tracks.driver_id = driver.id
LEFT JOIN persons as recipient ON tracks.recipient_id = recipient.id
WHERE id = $1 LIMIT 1;

Configuration

version: '2'
sql:
  - engine: 'postgresql'
    queries: 'query.sql'
    schema: 'migrations'
    gen:
      go:
        package: 'db'
        out: 'db'
        sql_package: 'pgx/v5'
        emit_json_tags: true
        emit_pointers_for_null_types: true
        emit_all_enum_values: true
        overrides:
          - go_struct_tag: 'json:"-"'
            column: '*.password'

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

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions