Skip to content

Scalar subquery in SELECT fails when used inside derived table in FROM (possibly related to #1264) #2476

@Victorabade

Description

@Victorabade

Hi! I found what seems to be another case related to subqueries inside derived tables, possibly related to #1264.

Problem

A scalar subquery in the SELECT list works by itself, but fails when that SELECT is wrapped as a derived table in FROM.

The error thrown is: text TypeError: Cannot read properties of undefined (reading '0')

Minimal reproducible example

This works:
SELECT (SELECT COUNT(*) FROM tarefas_roadmap_geral) AS qt FROM tarefas_roadmap_geral

But this fails:

SELECT * FROM ( SELECT (SELECT * FROM tarefas_roadmap_geral) FROM tarefas_roadmap_geral ) p
I was also able to simplify it further and noticed that the problem is not specific to COUNT(*). Even changing the inner scalar subquery shape still leads to the same failure pattern.

Additional notes

I originally found this in a bigger query involving UNION ALL, but after simplifying the SQL, it seems the issue can be reproduced without UNION, GROUP BY, or outer aggregation.

So the minimal failing pattern seems to be:

SELECT * FROM ( SELECT (SELECT ...) FROM ... ) p

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions