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

When selecting everything from a joined result, column contents are incorrect in one of my use cases. #3349

Closed
monetdb-team opened this issue Nov 30, 2020 · 0 comments

Comments

@monetdb-team
Copy link

@monetdb-team monetdb-team commented Nov 30, 2020

Date: 2013-08-22 11:34:40 +0200
From: Robin Cijvat <>
To: SQL devs <>
Version: 11.15.11 (Feb2013-SP3)
CC: @njnes

Last updated: 2013-09-27 13:47:13 +0200

Comment 19051

Date: 2013-08-22 11:34:40 +0200
From: Robin Cijvat <>

User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.89 Safari/537.36
Build Identifier:

Instead of showing the left and right result next to each other, the right result is displayed twice next to each other.

Reproducible: Always

Steps to Reproduce:

Execute the following SQL:

CREATE TABLE test (x int, y int);
insert into test (x, y) VALUES (1, 1);
insert into test (x, y) VALUES (1, 2);

SELECT *
FROM (
SELECT a1.x, a1.y, a2.x, a2.y
FROM (
SELECT *
FROM test
) AS a1 JOIN (
SELECT *
FROM test
) AS a2 ON a1.x = a2.x
) AS t;

Actual Results:

+------+------+------+------+
| x | y | x | y |
+======+======+======+======+
| 1 | 1 | 1 | 1 |
| 1 | 2 | 1 | 2 |
| 1 | 1 | 1 | 1 |
| 1 | 2 | 1 | 2 |
+------+------+------+------+

Expected Results:

+------+------+------+------+
| x | y | x | y |
+======+======+======+======+
| 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 2 |
| 1 | 2 | 1 | 1 |
| 1 | 2 | 1 | 2 |
+------+------+------+------+

Problem is fixed if the columns are given aliases as follows:
SELECT *
FROM (
SELECT a1.x AS x1, a1.y AS y1, a2.x AS x2, a2.y AS y2
FROM (
SELECT *
FROM test
) AS a1 JOIN (
SELECT *
FROM test
) AS a2 ON a1.x = a2.x
) AS t;

Comment 19053

Date: 2013-08-23 09:44:22 +0200
From: @njnes

Indeed we do not handle the first query correctly as it has ambiguous names.

Comment 19054

Date: 2013-08-23 10:04:56 +0200
From: Robin Cijvat <>

Ok, but the syntax of the outer query suggests that everything gets selected that is selected in the inner query, despite the naming of the columns. In the case it is left this way, won't it be a good idea to at least let this sort of construct trigger an error? Otherwise it might lead to confusion or even the usage of wrong query results if someone (like myself) assumes wrong things about these sort of queries.

Comment 19055

Date: 2013-08-23 10:55:59 +0200
From: @njnes

added an error for duplicate column names

Comment 19056

Date: 2013-08-23 11:42:02 +0200
From: MonetDB Mercurial Repository <>

Changeset 2810a6a4ef0e made by Niels Nes niels@cwi.nl in the MonetDB repo, refers to this bug.

For complete details, see http//devmonetdborg/hg/MonetDB?cmd=changeset;node=2810a6a4ef0e

Changeset description:

fixed bug #3349, ie check for duplicate column names after table level rename.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant