Skip site navigation (1) Skip section navigation (2)

Re: Bug #691: CREATE TABLE AS ignores explicit column names with UNION

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: treed(at)kojents(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: Bug #691: CREATE TABLE AS ignores explicit column names with UNION
Date: 2002-06-13 02:11:26
Message-ID: 15643.1023934286@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugs
pgsql-bugs(at)postgresql(dot)org writes:
> CREATE TABLE AS ignores explicitly specified column names when the query contains a UNION.  This is illustrated in the example below.

Good catch!  If you need a fix immediately, I think the attached patch
will do the trick.  (Line numbers are for current sources, but it should
patch cleanly into 7.2.*)  I have not tested it extensively though, so
there might be side-effects...

			regards, tom lane

*** src/backend/parser/analyze.c.orig	Tue May 28 18:15:42 2002
--- src/backend/parser/analyze.c	Wed Jun 12 21:49:56 2002
***************
*** 2212,2219 ****
--- 2212,2227 ----
  		qry->isBinary = FALSE;
  	}
  
+ 	/*
+ 	 * Any column names from CREATE TABLE AS need to be attached to both the
+ 	 * top level and the leftmost subquery.  We do not do this earlier
+ 	 * because we do *not* want the targetnames list to be affected.
+ 	 */
  	if (intoColNames)
+ 	{
  		applyColumnNames(qry->targetList, intoColNames);
+ 		applyColumnNames(leftmostQuery->targetList, intoColNames);
+ 	}
  
  	/*
  	 * As a first step towards supporting sort clauses that are

In response to

pgsql-bugs by date

Next:From: lewwidDate: 2002-06-13 05:12:17
Subject: to_date problem.
Previous:From: pgsql-bugsDate: 2002-06-12 22:48:26
Subject: Bug #691: CREATE TABLE AS ignores explicit column names with UNION

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group