Skip to content

Allow referencing grandparent fields #15981

Open
@hlcianfagna

Description

@hlcianfagna

Problem Statement

When writing certain analytical queries it is useful to be able to refer to "grandparent" fields, for instance:

WITH myvalues
AS (
	SELECT 1 AS a
	)
SELECT (
		SELECT subquery1.a
		FROM (
			SELECT a.b as a
			FROM generate_series(1, 2) a(b)
			WHERE a.b = myvalues.a
			) subquery1
		)
FROM myvalues;

This currently fails with:

UnsupportedFeatureException[Cannot use relation "myvalues" in this context. Can only access columns of an immediate parent, not a grandparent]

However in PostgreSQL it is accepted:

 a 
---
 1
(1 row

Possible Solutions

Resolve field names like in PostgreSQL

Considered Alternatives

Depends on the situation, in some queries it is for instance possible to bring filtering one level up, into a CTE, using arrays, and then process them with array expressions at a single-row level.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions