Skip to content

Commit

Permalink
sql: allow UNION with hidden and non-hidden columns
Browse files Browse the repository at this point in the history
This commit removes an assertion that required corresponding columns on
each side of a UNION to be both hidden or non-hidden.

Prior to this change, the following statements would yield the error:
"UNION types cannot be matched".

  CREATE TABLE ab (a INT, b INT);
  SELECT a, b, rowid FROM ab UNION VALUES (1, 2, 3);

With this commit, the above statements are executed without error.

Release note (bug fix): Fixed an incorrect error the ocurred when
executing UNION statements with hidden and non-hidden columns.
  • Loading branch information
mgartner committed Apr 8, 2020
1 parent 06c1077 commit c1fcaee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/union
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,8 @@ query T rowsort
{2}
NULL
{3}

# Allow UNION of hidden and non-hidden columns.
statement ok
CREATE TABLE ab (a INT, b INT);
SELECT a, b, rowid FROM ab UNION VALUES (1, 2, 3);
4 changes: 0 additions & 4 deletions pkg/sql/union.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package sql

import (
"context"
"fmt"

"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
Expand Down Expand Up @@ -114,9 +113,6 @@ func (p *planner) newUnionNode(
return nil, pgerror.Newf(pgcode.DatatypeMismatch,
"%v types %s and %s cannot be matched", typ, l.Typ, r.Typ)
}
if l.Hidden != r.Hidden {
return nil, fmt.Errorf("%v types cannot be matched", typ)
}
if l.Typ.Family() == types.UnknownFamily {
unionColumns[i].Typ = r.Typ
}
Expand Down

0 comments on commit c1fcaee

Please sign in to comment.