You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug When Using Table Aliases: table alias "all_users" does not exist #3169
Sqlc encounters issues when attempting to recognize table aliases specified within the WHERE clause, particularly when filtering selections using the syntax alias_table.field = 'something'.
I've provided a simple example to replicate the issue
Relevant log output
sqlc generate failed.
# package
query.sql:8:39: table alias"all_users" does not exist
Database schema
-- Create users tableCREATETABLEusers (
id SERIALPRIMARY KEY,
email VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create posts tableCREATETABLEadmins (
id SERIALPRIMARY KEY,
email VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
SQL queries
-- name: GetAllUsers :many
WITH all_users AS (
SELECT id, email FROM users
UNIONSELECT id, email FROM admins
)
SELECT id, email FROM all_users whereall_users.email=$1;
Same thing here: when i set my where condition to a constant it works, but when the condition is dynamic, i get error:
WHERE models.make_id = 47; this works WHERE models.make_id = @in_make_id; this on does not WHERE models.make_id = (sqlc.arg(in_make_id)); this one neither
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?
Same thing here: when i set my where condition to a constant it works, but when the condition is dynamic, i get error:
WHERE models.make_id = 47; this works WHERE models.make_id = @in_make_id; this on does not WHERE models.make_id = (sqlc.arg(in_make_id)); this one neither
same issue here with sqlite
this seems to work for me: WHERE models.make_id = cast(sqlc.arg(in_make_id) as integer);
Reacted by Matthew Skovranek, supressionstop and Florian Franke
@kyleconroy a vanilla use case in probably the most popular non-embedded database, postgres (and seemingly also the most popular embedded database, sqlite), is broken, with a bad error message to boot. Can we get a TTR for this bug, guidance on acceptable PRs, or anything at all?
Activity
matteobassan commentedon Feb 21, 2024
Same thing here: when i set my where condition to a constant it works, but when the condition is dynamic, i get error:
WHERE models.make_id = 47;this worksWHERE models.make_id = @in_make_id;this on does notWHERE models.make_id = (sqlc.arg(in_make_id));this one neitherJille commentedon Feb 27, 2024
I expect #3220 to fix this
Dmdv commentedon May 15, 2024
I have the same, table aliases are not recognaized
Dmdv commentedon 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
frbrno commentedon Jun 3, 2024
same issue here with sqlite
this seems to work for me:
WHERE models.make_id = cast(sqlc.arg(in_make_id) as integer);dkrieger commentedon Jul 1, 2024
@kyleconroy a vanilla use case in probably the most popular non-embedded database, postgres (and seemingly also the most popular embedded database, sqlite), is broken, with a bad error message to boot. Can we get a TTR for this bug, guidance on acceptable PRs, or anything at all?
rob2244 commentedon Jul 24, 2024
+1 having this same issue, super annoying makes where clauses based on CTE's basically unusable
brojonat commentedon Aug 26, 2024
Yeah, casting seems to remedy this, for whatever reason.
WHERE models.make_id = @in_make_id::INTEGER;works for me with postgres.AvicennaJr commentedon Oct 20, 2025
Please do not click that link as it is malicious. Maintainers kindly remove that comment.
For anyone curious, this is the sites code: