sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Table alias not working

Open FreshPer opened this issue 3 years ago • 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

FreshPer avatar Jan 21 '22 06:01 FreshPer

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

david-alza avatar Jul 06 '22 14:07 david-alza

Hello,

Does someone has a workaround?

tcastelly avatar Nov 29 '22 10:11 tcastelly

Any update on this?

ChurchOfTheSubgenius avatar May 10 '23 07:05 ChurchOfTheSubgenius

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

smantic avatar Jun 01 '23 01:06 smantic