Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table alias not working #1385

Open
FreshPer opened this issue Jan 21, 2022 · 5 comments
Open

Table alias not working #1385

FreshPer opened this issue Jan 21, 2022 · 5 comments

Comments

@FreshPer
Copy link

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

@FreshPer FreshPer added bug Something isn't working triage New issues that hasn't been reviewed labels Jan 21, 2022
@kyleconroy kyleconroy added 📚 mysql 💻 darwin 🔧 golang and removed triage New issues that hasn't been reviewed labels Jan 26, 2022
@david-alza
Copy link

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

@tcastelly
Copy link

Hello,

Does someone has a workaround?

@ChurchOfTheSubgenius
Copy link

Any update on this?

@smantic
Copy link

smantic commented Jun 1, 2023

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
Copy link

Dmdv commented May 15, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants