Skip to content

LEFT JOIN not generating Null* types with table aliases#1897

@fr3fou

Description

@fr3fou

Version

1.15.0

What happened?

sqlc generates incorrect code when using table aliases inside left joins.
#1491 was supposed to fix it, but I'm still able to reproduce it.
The StripeID field should be of type sql.NullString but it isn't.

Relevant log output

No response

Database schema

CREATETABLEusers ( user_id uuid primary key ); CREATETABLEuser_stripe_customers ( user_id uuid NOT NULL, stripe_id TEXTNOT NULL, UNIQUE (user_id, stripe_id) ); ALTERTABLE user_stripe_customers ADD FOREIGN KEY (user_id) REFERENCES users (user_id) ONUPDATE CASCADE ON DELETE CASCADE;

SQL queries

-- name: GetStripeUserByUserID :oneSELECT stripe_id, users.user_idFROM users LEFT JOIN user_stripe_customers ONusers.user_id=user_stripe_customers.user_idWHEREusers.user_id= @user_id; -- name: GetStripeUserByUserIDBroken :oneSELECT stripe_id, u.user_idFROM users u LEFT JOIN user_stripe_customers usu ONu.user_id=usu.user_idWHEREu.user_id= @user_id;

Configuration

{"version": "1","packages": [{"path": "db","engine": "postgresql","schema": "query.sql","queries": "query.sql"}]}

Playground URL

https://play.sqlc.dev/p/4827a9efa8fd793d7ee704f877890af04675aa382a3942d0f9807a95ae779cf7

What operating system are you using?

macOS

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