Skip to content

Columns not found when joining subquery #467

@maxhawkins

Description

@maxhawkins

If you define a new column in a subquery and do a join the new column can't be referenced by the containing query. A "does not exist" error is returned.

An example:

CREATE TABLE users (
    user_id INT PRIMARY KEY
);
CREATE TABLE names (
    user_id INT REFERENCES users,
    first_name TEXT,
    last_name TEXT
);

SELECT
    user_id,
    full_name
FROM users
JOIN (
    SELECT
        user_id,
        first_name || last_name AS full_name
    FROM names
) AS full_names USING (user_id);

Returns column "full_name" does not exist, though the query is valid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions