Thread: BUG: Each UNION | EXCEPT | INTERSECT query must have the same number of columns.

BUG: Each UNION | EXCEPT | INTERSECT query must have the same number of columns.

From
Jacek Konieczny
Date:
Your name               : Jacek Konieczny
Your email address      : jajcus@bnet.pl


System Configuration
---------------------
  Architecture (example: Intel Pentium)         : AMD K6-II 3DNow

  Operating System (example: Linux 2.0.26 ELF)  : Linux 2.4.2 ELF  (PLD Distribution)

  PostgreSQL version (example: PostgreSQL-7.0):   PostgreSQL-7.0.3

  Compiler used (example:  gcc 2.8.0)           : probably 2.95.3


Please enter a FULL description of your problem:
------------------------------------------------
When using query with EXCEPT clause in INSERT command sometime
false "ERROR:  Each UNION | EXCEPT | INTERSECT query must have the same
number of columns." is generated, and the command fails.
Probably default values are added to the first query before it
is compared to the second one.


Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------
CREATE TABLE tb1 ( a CHARACTER(10) DEFAULT 'abc', b CHARACTER(10));
CREATE TABLE tb2 ( a CHARACTER(10), b CHARACTER(10));
INSERT INTO tb1(b) SELECT b FROM tb2 EXCEPT SELECT b FROM tb1;

If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------
I would have to check the source code...
Jacek Konieczny <jajcus@bnet.pl> writes:
> CREATE TABLE tb1 ( a CHARACTER(10) DEFAULT 'abc', b CHARACTER(10));
> CREATE TABLE tb2 ( a CHARACTER(10), b CHARACTER(10));
> INSERT INTO tb1(b) SELECT b FROM tb2 EXCEPT SELECT b FROM tb1;

This is fixed for 7.1.

            regards, tom lane