Closed
Description
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
CREATE TABLE users (
user_id uuid primary key
);
CREATE TABLE user_stripe_customers
(
user_id uuid NOT NULL,
stripe_id TEXT NOT NULL,
UNIQUE (user_id, stripe_id)
);
ALTER TABLE user_stripe_customers
ADD FOREIGN KEY (user_id) REFERENCES users (user_id) ON UPDATE CASCADE ON DELETE CASCADE;
SQL queries
-- name: GetStripeUserByUserID :one
SELECT stripe_id, users.user_id
FROM users
LEFT JOIN user_stripe_customers ON users.user_id = user_stripe_customers.user_id
WHERE users.user_id = @user_id;
-- name: GetStripeUserByUserIDBroken :one
SELECT stripe_id, u.user_id
FROM users u
LEFT JOIN user_stripe_customers usu ON u.user_id = usu.user_id
WHERE u.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