Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate columns are allowed in materialized views? #9158

Closed
1 of 7 tasks
Linksku opened this issue Nov 17, 2021 · 3 comments · Fixed by #9162
Closed
1 of 7 tasks

Duplicate columns are allowed in materialized views? #9158

Linksku opened this issue Nov 17, 2021 · 3 comments · Fixed by #9162
Assignees
Labels
C-bug Category: something is broken

Comments

@Linksku
Copy link

Linksku commented Nov 17, 2021

What version of Materialize are you using?

materialized v0.9.10 (8d7b550fb)

How did you install Materialize?

  • Docker image
  • Linux release tarball
  • APT package
  • macOS release tarball
  • Homebrew tap
  • Built from source
  • Materialize Cloud

What was the issue?

Materialize allows multiple columns with the same name. E.g.:

materialize=> create materialized view test as id, id, id from posts;
CREATE VIEW
materialize=> select * from test;
 id | id | id 
----+----+----
  1 |  1 |  1 
  2 |  2 |  2
  3 |  3 |  3

This prevents selecting the duplicate column:

materialize=> select id from test;
ERROR:  column name "id" is ambiguous

I'm relatively new to Postgres, but it looks like this isn't allowed in Postgres:

foo=# create materialized view test as id, id, id from posts;
ERROR:  column "id" specified more than once

Is the issue reproducible? If so, please provide reproduction instructions.

The queries above consistently repro.

Please attach any applicable log files.

Nothing relevant

@Linksku Linksku added the C-bug Category: something is broken label Nov 17, 2021
@sploiselle sploiselle self-assigned this Nov 17, 2021
@umanwizard
Copy link
Contributor

You can rename the columns in the select query:

materialize=> create table t (id int);
CREATE TABLE
materialize=> insert into t values (1);
INSERT 0 1
materialize=> create view v as select id, id + 1 id from t;
CREATE VIEW
materialize=> select * from v;
 id | id 
----+----
  1 |  2
(1 row)
materialize=> select id_b from v as v (id_a, id_b);
 id_b 
------
    2
(1 row)

@Linksku
Copy link
Author

Linksku commented Nov 17, 2021

Thanks for checking, seems like this is an intended feature. I'm curious why duplicate column names are allowed?

In my case, it was caused by a bug. I don't see why anyone would intentionally have duplicate column names.

@sploiselle
Copy link
Contributor

@Linksku I think @umanwizard's suggestion is a viable workaround in the short term but am putting up a PR to prohibit this behavior in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: something is broken
Projects
SQL and Coordinator
Awaiting triage
Development

Successfully merging a pull request may close this issue.

3 participants