sqlc-dev/sqlc

Table alias not working

FreshPer opened this issue · 5 comments

Version

1.11.0

What happened?

In v1.11.0, when I use an alias for a subquery table, sqlc will report an error for table alias does not exist, but when I change version to v1.10.0 everything is fine

Relevant log output

table alias "subtable" does not exist

Database schema

No response

SQL queries

`
select a.name
from (a subquery) as a
where a.id=?

`

Configuration

No response

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Just wanted to add that this also affects Postgres in both CTE's and subqueries. Here's two very simple (and contrived) examples:
Subquery: https://play.sqlc.dev/p/cf2acd78ff8b83b83a063e13279341de0ddd7dfa7c27a6be7506d90fec3d7aa5
CTE: https://play.sqlc.dev/p/8ce7e58a669066fd890a557ed9fbaaebb3902cf83cd6890ba5a5cfe95805cc75

Hello,

Does someone has a workaround?

Any update on this?

casting the type of the placeholder seems to be a work around.
See: https://play.sqlc.dev/p/13001a43c6063935dd690269b5e9c640a9632f3f478680b628724e1da9cf6483

Also wanted to mention this is only an issue when you have
subquery_alias.column = $<placeholder>
subquery_alias.column = 'static_value' works just fine

Dmdv commented

Hi everyone
This error persist since 2022.
Can someone ping the pull request #3220
How one can possibly work without CTE or joins?
Is SQLC only for primitive cases?

Please, pay attention to issues:
#2400
#3169
#1385

Though the solution of @smantic works well:
#1385 (comment)