Skip to content

parser: Support columns from subselect statements - #489

Merged
kyleconroy merged 1 commit into
sqlc-dev:masterfrom
maxhawkins:master
May 14, 2020
Merged

kyleconroy merged 1 commit into
sqlc-dev:masterfrom
maxhawkins:master

Conversation

@maxhawkins

Copy link
Copy Markdown
Contributor

Fixes #467

@kyleconroy
kyleconroy merged commit 19dda2b into sqlc-dev:master May 14, 2020
@peteole

peteole commented Mar 29, 2022

Copy link
Copy Markdown

Cool that it works, however there is still an issue when using joins in a subselect statement.
Take this example:

SELECT r.*
FROM (
        project_saves
        JOIN projects
        ON project_saves.project_id = projects.id
    ) r;

This fails with the message

# package sqlc
sql-queries/projects.sql:159:1: empty edit contents

sqlc seems to believe that thesubselect r has no columns since when selecting a field of r the error message is "column "id" does not exist". Is there an easy way to fix this?

@gwillem

gwillem commented Jul 7, 2025 •

Copy link
Copy Markdown
Contributor

Also, subquery aliasing does not work when sqlc.arg is used

SELECT *
FROM (SELECT * FROM report LIMIT ...) AS r
JOIN ... 
WHERE r.created_at >= sqlc.arg('since')
table alias "r" does not exist

(I need to do pre-filtering, if I do a flat join, MySQL runs out of sort memory)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Columns not found when joining subquery

4 participants