Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 4B6861337B9D for ; Tue, 1 Mar 2011 19:38:02 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 27742-02 for ; Tue, 1 Mar 2011 23:37:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com [209.85.216.181]) by mail.postgresql.org (Postfix) with ESMTP id BB02B1336971 for ; Tue, 1 Mar 2011 19:37:54 -0400 (AST) Received: by qyg14 with SMTP id 14so4858643qyg.19 for ; Tue, 01 Mar 2011 15:37:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=fXdXvDrIyadZikbKmvAF6+UoyXwH/7sRMyjJt0w0jIA=; b=ajWu+FwcTCr7Mc+0CNH75Z1Oniv8hyu68A7WJm+riPnLiF3c0JGtz6B+kF3vUA2Fjj rrB2qL6mgpRjCtWvOn+IVRAxH+XRP8q7IaELv69jXhyfTZ6bn2pTpsFPZpzfFGdEVCh3 XQHAd3i774ymql4xhdFQd2kuSzM1PU3jnhwgI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=wWydIp+TjUgcsc0+1AjyBBJy/Aim7JsQVznAJy0+DDN7YrbNbhOyWdO0HwVlpG+KBk PnzmifB17UwzIAKoucEQ0LJsjKa8C51tHVpolHumEflEaLOADsSCLKIk/2EpfOhA+YX8 MsHCKpRBtDxmElHI9SvoyqRHviB/nxf565HaI= Received: by 10.229.114.223 with SMTP id f31mr1941570qcq.289.1299022674624; Tue, 01 Mar 2011 15:37:54 -0800 (PST) Received: from [192.168.1.4] (ool-44c5dd75.dyn.optonline.net [68.197.221.117]) by mx.google.com with ESMTPS id t7sm4445271qcs.28.2011.03.01.15.37.52 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 01 Mar 2011 15:37:54 -0800 (PST) Message-ID: <4D6D834A.50405@gmail.com> Date: Tue, 01 Mar 2011 18:37:46 -0500 From: Stephen Cook User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 To: S G CC: Rob Sargent , pgsql-sql@postgresql.org Subject: Re: distinguishing identical columns after joins References: <4D6D4EC2.70306@gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201103/7 X-Sequence-Number: 35209 In times like these, I usually write a query using information_schema.columns to generate the column list: SELECT ordinal_position, 1 AS table_instance, 'a.' || column_name || ' AS ' || column_name || '_a,' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'your_table_here' UNION ALL SELECT ordinal_position, 2 AS table_instance, 'b.' || column_name || ' AS ' || column_name || '_b,' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'your_table_here' ORDER BY table_instance, ordinal_position; Or something along those lines, and copy-and-paste the results into the query. It's quicker than typing them all out once you hit a certain number of columns, and certainly less typo-prone. It's not the shortcut you were thinking of but it works. On 3/1/2011 5:13 PM, S G wrote: > Rob, what you wrote certainly does work. But suppose you had to do > that for a join with 50 columns in each table, and you really needed > to see all those columns show up in the final result set, and > furthermore, you needed to be able to identify each one uniquely in > the final result set. Explicit renaming works, but it's tedious. > Call me lazy. I'm hoping a column-renaming shortcut exists that works > with the "SELECT *" concept.