Skip to content

Unexpected Error of alias which redefines column name in join #10276

Closed

Description

@sanyfan

Alias of the redefined column name in multi join

How to reproduce
version 19.17.6.36
Normal Case

SELECT 
    sum(x.n) as n1,
    sum(z.n) as n2
FROM
(
    SELECT 1000 AS n,1 as id
) AS x 
join (select 10000 as n,1 as id) as y 
on x.id = y.id 
left join (select 100000 as n,1 as id) as z 
on x.id = z.id 

Result

n1 n2
1000 100000

Unexpected Case

SELECT 
    sum(x.n) as n,
    sum(z.n) as n2
FROM
(
    SELECT 1000 AS n,1 as id
) AS x 
join (select 10000 as n,1 as id) as y 
on x.id = y.id 
left join (select 100000 as n,1 as id) as z 
on x.id = z.id 

Result
Code: 10, e.displayText() = DB::Exception: Not found column n in block. There are only columns: --x.n, --x.id (version 19.17.6.36 (official build))

I also met another Error in the SQL with the same struct

Code: 47, e.displayText() = DB::Exception: Unknown identifier: booked_guaranteed_narrower_or_equal (version 19.17.6.36 (official build))

So how to solve this problem?

Activity

  1. added
    unexpected behaviour
    on Apr 15, 2020
  2. self-assigned this
    on Apr 15, 2020
  3. 4ertus2 commented on Jun 3, 2020

    @4ertus2
    Contributor

    Similar problem with simple join. Redefinition of x:

    CREATE TABLE t (`x` UInt32, `lc` LowCardinality(String)) ENGINE = Memory;
    CREATE TABLE nr (`x` Nullable(UInt32), `lc` Nullable(String)) ENGINE = Memory;
    
    INSERT INTO t VALUES (0, 'str');
    INSERT INTO nr VALUES (0, 'str');
    
    SELECT r.lc, length(r.lc) x FROM t AS l LEFT JOIN nr AS r USING (x);
    
    DB::Exception: Unknown identifier: r.lc
    
  4. changed the title [-]Unexpected Error of alias which redefines column name in multi join[/-] [+]Unexpected Error of alias which redefines column name in join[/+] on Jun 3, 2020
  5. removed their assignment
    on Oct 16, 2020
  6. alexey-milovidov commented on Mar 20, 2023

    @alexey-milovidov
    Member

    Works perfectly with Analyzer. We will close it after enabling Analyzer by default.

  7. added a commit that references this issue on Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    unexpected behaviour

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions