Skip to content

Using alias in simple view #11068

Closed

Description

@andrelec1

I try to make a view... for the moment i have this request :

drop table if exists computed_datum_hours;
create view computed_datum_hours as
select
    toStartOfHour(b.datetime_value) as datetime_desc,
    b.computed_id,
    b.computed_kind,
    b.computed_type,
    sum(b.value) as value
from computed_datum as b
group by
    b.computed_id,
    b.computed_kind,
    b.computed_type,
    toStartOfHour(b.datetime_value)
;

but clickhouse say :
Code: 47, e.displayText() = DB::Exception: Missing columns: 'b.value' 'b.datetime_value' 'b.computed_type' 'b.computed_kind' 'b.computed_id' while processing query: 'SELECT toStartOfHour(b.datetime_value) AS datetime_desc, b.computed_id, b.computed_kind, b.computed_type, sum(b.value) AS value FROM api_client.computed_datum GROUP BY b.computed_id, b.computed_kind, b.computed_type, toStartOfHour(b.datetime_value)', required columns: 'b.computed_id' 'b.computed_kind' 'b.computed_type' 'b.datetime_value' 'b.value', source columns: 'flags' 'computed_type' 'datetime_value' 'uuid' 'value' 'computed_id' 'insert' 'computed_kind' 'EventDateTime' (version 20.4.2.9 (official build))

this is a bug or alias is different from mariadb ?
( PS, if i remove every alias to b , the view work )

Activity

  1. added
    bug
    comp-view
    and removed
    question
    on May 20, 2020
  2. den-crane commented on May 20, 2020

    @den-crane
    Contributor

    STR:

    
    create table vt(datetime_value DateTime, value Float64) Engine=Memory;
    
    create view computed_datum_hours as
    SELECT
            toStartOfHour(b.datetime_value) AS datetime_desc,
            sum(b.value) AS value
    FROM vt AS b
    GROUP BY toStartOfHour(b.datetime_value)
    
    Received exception from server (version 20.3.8):
    Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Missing columns: 'b.value'
    
    
    
    SELECT
        toStartOfHour(b.datetime_value) AS datetime_desc,
        sum(b.value) AS value
    FROM vt AS b
    GROUP BY toStartOfHour(b.datetime_value)
    
    Ok.
    
    0 rows in set. Elapsed: 0.003 sec.
    
  3. PHaroZ commented on Sep 11, 2020

    @PHaroZ

    The same here with a more simple query

    CREATE OR REPLACE view testView as SELECT t.number FROM numbers AS t
            
    [2020-09-11 09:15:59] Code: 47, e.displayText() = DB::Exception: Missing columns: 't.number' while processing query: 'SELECT t.number FROM system.numbers', required columns: 't.number', source columns: 'number' (version 20.6.4.44 (official build))
    

    A simple workaround is to prefix table with its database name :

    CREATE OR REPLACE view testView as SELECT t.number FROM system.numbers AS t
            
    [2020-09-11 09:16:38] completed in 105 ms
    

    My CH version is 20.6.4.44

  4. filimonov commented on Oct 12, 2020

    @filimonov
    Contributor

    Old versions had the same issue.

    Received exception from server (version 18.16.1):
    Code: 47. DB::Exception: Received from localhost:9000, 127.0.0.1. DB::Exception: Unknown identifier: b.value.  
    
    Received exception from server (version 19.11.14):
    Code: 47. DB::Exception: Received from localhost:9000. DB::Exception: Missing columns: 'b.datetime_value' 'b.value' while processing query: 'SELECT toStartOfHour(b.datetime_value) AS datetime_desc, sum(b.value) AS value FROM default.vt GROUP BY toStartOfHour(b.datetime_value)', required columns: 'b.datetime_value' 'b.value', source columns: 'value' 'datetime_value'. 
    
    
  5. andrelec1 commented on Oct 14, 2020

    @andrelec1
    Author

    Affect last version too
    version 20.9.2.20 (official build)

    [2020-10-14 17:12:32] Code: 47, e.displayText() = DB::Exception: Missing columns: 'b.value' 'b.datetime_value' while processing query: 'SELECT toStartOfHour(b.datetime_value) AS datetime_desc, sum(b.value) AS value FROM api_client.vt GROUP BY toStartOfHour(b.datetime_value)', required columns: 'b.datetime_value' 'b.value', source columns: 'value' 'datetime_value' (version 20.9.2.20 (official build))
    

    PS: Think 20.7 ans 20.8 is affected too ...

  6. sah4ez commented on Jan 31, 2021

    @sah4ez

    I got the same error, but when I add the database name, a view was created.

  7. andrelec1 commented on Dec 6, 2021

    @andrelec1
    Author

    any news ?

  8. NpDen4ik commented on Mar 21, 2022

    @NpDen4ik

    Still no solution please fix it

  9. Gachegov59 commented on Mar 21, 2022

    @Gachegov59

    please fix it 🙂

  10. Nicholas-Kant commented on Mar 21, 2022

    @Nicholas-Kant

    please fix it 🙏

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

    bugcomp-view

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions