sqlc-dev / sqlc

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

Sqlc could not support table alias (error: table alias "t1" does not exist) #2400

Open ankisme opened 1 year ago

ankisme commented 1 year ago

Version

1.18.0

What happened?

Sqlc could not support table alias, the sql example is in below.

The error message is "table alias "t1" does not exist"

Relevant log output

No response

Database schema

CREATE TABLE authors (
          id   BIGINT PRIMARY KEY AUTO_INCREMENT,
          name text      NOT NULL,
          bio  text
);

SQL queries

/* name: ListAuthors2 :many */
select * from (SELECT * FROM authors) as t1 where t1.id > ?;

Configuration

No response

Playground URL

No response

What operating system are you using?

No response

What database engines are you using?

No response

What type of code are you generating?

No response

Dmdv commented 6 months ago

Hi everyone This error persist since 2022. Can someone ping the pull request https://github.com/sqlc-dev/sqlc/pull/3220 How one can possibly work without CTE or joins? Is SQLC only for primitive cases?

Please, pay attention to issues: https://github.com/sqlc-dev/sqlc/issues/2400 https://github.com/sqlc-dev/sqlc/issues/3169 https://github.com/sqlc-dev/sqlc/issues/1385

Though the solution of @smantic works well: https://github.com/sqlc-dev/sqlc/issues/1385#issuecomment-1571187337