Skip to content

Altering columns on underlying table has no effect on view create statement when using SELECT * #19087

Closed

Description

@buyology

on ClickHouse server version 20.12.4 revision 54442:

b2344c4eb05b :) CREATE TABLE tbl ( a String ) ENGINE = MergeTree() ORDER BY a

Ok.

0 rows in set. Elapsed: 0.010 sec.

b2344c4eb05b :) CREATE VIEW tbl_view AS SELECT * FROM tbl

Ok.

0 rows in set. Elapsed: 0.008 sec.

b2344c4eb05b :) ALTER TABLE tbl ADD COLUMN b String ALIAS a

Ok.

0 rows in set. Elapsed: 0.008 sec.

b2344c4eb05b :) SELECT b FROM tbl_view

Received exception from server (version 20.12.4):
Code: 47. DB::Exception: Received from host.docker.internal:9000. DB::Exception: Missing columns: 'b' while processing query: 'SELECT b FROM (SELECT * FROM default.tbl) AS tbl_view', required columns: 'b', source columns: 'a'.

0 rows in set. Elapsed: 0.007 sec.

I guess the problem lies in the create tables query:

b2344c4eb05b :) SELECT create_table_query FROM system.tables WHERE name = 'tbl_view'

┌─create_table_query─────────────────────────────────────────────────────┐
│ CREATE VIEW default.tbl_view (`a` String) AS SELECT * FROM default.tbl │
└────────────────────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.032 sec.

However it is not possible to replace the view either:

b2344c4eb05b :) CREATE OR REPLACE VIEW tbl_view AS SELECT * FROM tbl

Ok.

0 rows in set. Elapsed: 0.007 sec.

b2344c4eb05b :) SELECT create_table_query FROM system.tables WHERE name = 'tbl_view'

┌─create_table_query─────────────────────────────────────────────────────┐
│ CREATE VIEW default.tbl_view (`a` String) AS SELECT * FROM default.tbl │
└────────────────────────────────────────────────────────────────────────┘

1 rows in set. Elapsed: 0.035 sec.

Activity

  1. added
    bug
    on Jan 14, 2021
  2. changed the title [-]Altering columns on underlying table has no effect on create statement when using SELECT *[/-] [+]Altering columns on underlying table has no effect on view create statement when using SELECT *[/+] on Jan 14, 2021
  3. added
    question
    unexpected behaviour
    comp-view
    and removed
    bug
    question
    on Jan 14, 2021
  4. alexey-milovidov commented on Oct 19, 2022

    @alexey-milovidov
    Member

    This is expected. Views' structure is determined at creation time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

comp-viewquestion-answeredunexpected behaviour

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions