Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YsDZP-0004sg-HT for pgsql-sql@arkaria.postgresql.org; Tue, 12 May 2015 17:02:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YsDZO-0001J2-T9 for pgsql-sql@arkaria.postgresql.org; Tue, 12 May 2015 17:02:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YsDZN-0001Iv-Qx for pgsql-sql@postgresql.org; Tue, 12 May 2015 17:02:13 +0000 Received: from proofpoint1.mail.rice.edu ([128.42.201.100] helo=pp1.rice.edu) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YsDZG-00024t-HC for pgsql-sql@postgresql.org; Tue, 12 May 2015 17:02:12 +0000 Received: from pps.filterd (pp1.rice.edu [127.0.0.1]) by pp1.rice.edu (8.14.5/8.14.5) with SMTP id t4CH24wj005936; Tue, 12 May 2015 12:02:05 -0500 Received: from mh1.mail.rice.edu (mh1.mail.rice.edu [128.42.201.20]) by pp1.rice.edu with ESMTP id 1ub651gc27-1; Tue, 12 May 2015 12:02:04 -0500 X-Virus-Scanned: by amavis-2.7.0 at mh1.mail.rice.edu, auth channel X-SMTP-Auth: no X-SMTP-Auth: no X-SMTP-Auth: no Received: from aart.rice.edu (aart.rice.edu [168.7.56.48]) by mh1.mail.rice.edu (Postfix) with ESMTP id AE3F3460454; Tue, 12 May 2015 12:02:01 -0500 (CDT) Received: by aart.rice.edu (Postfix, from userid 18612) id A285C100837; Tue, 12 May 2015 12:02:01 -0500 (CDT) Date: Tue, 12 May 2015 12:02:01 -0500 From: "ktm@rice.edu" To: "David G. Johnston" Cc: Jason Aleski , "pgsql-sql@postgresql.org" Subject: Re: ERROR: column "gid" specified more than once Message-ID: <20150512170201.GI31129@aart.rice.edu> References: <1431419471426-5848845.post@n5.nabble.com> <55521B89.1090900@gmail.com> <20150512155309.GH31129@aart.rice.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.20 (2009-12-10) X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 kscore.is_bulkscore=7.63833440942108e-14 kscore.compositescore=0 circleOfTrustscore=0 compositescore=0.995703810101747 suspectscore=0 recipient_domain_to_sender_totalscore=0 phishscore=0 bulkscore=0 kscore.is_spamscore=0 rbsscore=0.995703810101747 recipient_to_sender_totalscore=0 recipient_domain_to_sender_domain_totalscore=0 spamscore=0 recipient_to_sender_domain_totalscore=0 urlsuspectscore=0.995703810101747 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1505120218 X-Pg-Spam-Score: -4.2 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On Tue, May 12, 2015 at 09:19:23AM -0700, David G. Johnston wrote: > On Tue, May 12, 2015 at 9:09 AM, David G. Johnston < > david.g.johnston@gmail.com> wrote: > > > On Tue, May 12, 2015 at 8:53 AM, ktm@rice.edu wrote: > > > >> On Tue, May 12, 2015 at 08:49:53AM -0700, David G. Johnston wrote: > >> > On Tuesday, May 12, 2015, Jason Aleski wrote: > >> > > >> > > You probably need to specify your wildcard on both tables. > >> > > > >> > > CREATE TABLE "BorujerdDistCent" as > >> > > SELECT > >> > > "Borujerd".*, "Lorestan".*, > >> > > t_distance(st_centroid("Lorestan".geometry),"Borujerd".geometry)/1000 > >> > > as DistFromCntroid > >> > > FROM "Borujerd", "Lorestan" > >> > > > >> > > > >> > My bad on the assumed -bugs list from before... > >> > > >> > Anyway, how is this suugestion different from simply saying "*" without > >> a > >> > relation specification - which the OP did and it didn't work. > >> > > >> > David J. > >> > >> Because the column names are differentiated by their prefixes then: > >> > >> Borujerd.gid, Lorestan.gid > >> > >> No conflict. > >> > >> > > I suggest you test that theory out. > > > > > ​The reason why this advice is wrong is because the error is coming from > the CREATE TABLE AS portion and not the select query. > > ​Within the following:​ > > ​CREATE TABLE testtable AS > SELECT t1.*, t2.* > FROM ( VALUES (1::int) ) t1 (s) > CROSS JOIN ( VALUES (2::int) ) t2 (s)​ > > executing just the SELECT portion will indeed output a two-column result > with both columns named "s". > > However, it is not possible to create a table with two columns having the > same name and so using the exact same query will fail with the duplicate > name error. > > The only way to solve the problem is to alias the output columns or choose > not to output one of the columns. > > SELECT t1.s AS s_t1, t2.s AS s_t2 FROM [...] > or > SELECT t1.* FROM [...] > > As shown above column names in the result do not carry over their source > identifier - just the name itself. > > David J. Yes. You are correct. Sorry for the noise. Ken -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql