Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZeAga-0004O7-BG for pgsql-docs@arkaria.postgresql.org; Mon, 21 Sep 2015 23:39:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZeAgY-0005De-FF for pgsql-docs@arkaria.postgresql.org; Mon, 21 Sep 2015 23:39:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZeAgX-0005D7-GZ for pgsql-docs@postgresql.org; Mon, 21 Sep 2015 23:39:49 +0000 Received: from mail-io0-x22c.google.com ([2607:f8b0:4001:c06::22c]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZeAgP-0004U3-NK for pgsql-docs@postgresql.org; Mon, 21 Sep 2015 23:39:48 +0000 Received: by iofb144 with SMTP id b144so455201iof.1 for ; Mon, 21 Sep 2015 16:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=W1sranl7IRC4OhySHWD1dHIFlnxfsneNAMdC0D65DHE=; b=VsBn3Rep6m1twa4s28sQLd7CAB+nV/O9Q/GrRvySMhscOij5vzXsRciK4hJxoq8DXR ib0hzNKlWqcgAT72WYNESzMRSj6UUlSbuSaF2OlQNKbqEDdxGc6dzg+r6N+T8acx9HnY 6TyIBIaU3tK9QaPp7BO80BfwXeafNJmnZvmzHTDNY5gJcTmySukkLRyerryPCIIhHMwA RrEyK02kE1F+G5IPFYabVXfW8Afyg76+PmMqNsZZUYjwv+GvySOgyW1Kwd90O6K/ss/e z1pbH6+mW2Ig//0+0S5wyecJK/eoyNFwizlu9JwWVF0EPwjQ+/c9ZoYCeBPsT/BgO+VZ urMw== MIME-Version: 1.0 X-Received: by 10.107.161.144 with SMTP id k138mr32313011ioe.47.1442878778681; Mon, 21 Sep 2015 16:39:38 -0700 (PDT) Received: by 10.36.143.141 with HTTP; Mon, 21 Sep 2015 16:39:38 -0700 (PDT) In-Reply-To: References: Date: Mon, 21 Sep 2015 19:39:38 -0400 Message-ID: Subject: Re: Docs claim that "select myTable.*" wildcard won't let you assign column names From: "David G. Johnston" To: Amir Rohan Cc: "pgsql-docs@postgresql.org" Content-Type: multipart/alternative; boundary=001a1140faa80eb02405204a6507 X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org --001a1140faa80eb02405204a6507 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Monday, September 21, 2015, Amir Rohan wrote: > > From http://www.postgresql.org/docs/9.4/static/sql-select.html (and > previous version too): > ##SELECT List > <...> > Instead of an expression, * can be written in the output list as a > shorthand for all the columns of the selected rows. > Also, you can write table_name.* as a shorthand for the columns > coming from just that table. In these cases it is not > possible to specify new names with AS; the output column names will > be the same as the table columns' names. > > But, the docs elsewhere feature a query example show the use of a wildcar= d > for columns > as well as allowing you to assign names to as many of the leading columns > as you wish: > > WITH T0 as ( SELECT 1,2,3 ) > SELECT T0.* from T0 as T0(foo,bar) ; > > foo =E2=94=82 bar =E2=94=82 ?column? > =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > 1 =E2=94=82 2 =E2=94=82 3 > (1 row) > > The following curious variant also works: > > WITH T0 as ( SELECT 1,2,3 ) > SELECT justAnythingReally.* from T0 as justAnythingReally(foo,bar) ; > > The synoposis/grammer at the top doesn't hint at this either. I've checke= d > and this has been supported since at least 9.2 . > > Neither of those examples is: SELECT * AS "how would one alias this?" FROM table So what's your point? Obviously you can alias stuff before it makes its way into a select-list that refers to it using * In this case the FROM clause is what is being alised. It is documented though I'd need to look to identify the specific location. It would not be documented in a section regarding the select-list. David J. --001a1140faa80eb02405204a6507 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Monday, September 21, 2015, Amir Rohan <amir.rohan@mail.com> wrote:
=C2=A0

=C2=A0 ##SELECT List

=C2=A0=C2=A0=C2=A0 <...>
=C2=A0=C2=A0=C2=A0 Instead of an expression, * can be written= in the output list as a shorthand for all the columns of the selected rows= .
=C2=A0=C2=A0=C2=A0 Also, you can write table_name.* = as a shorthand for the columns coming from just that table. In these cases = it is not
=C2=A0=C2=A0=C2=A0 possible to specify new names with AS; the= output column names will be the same as the table columns' names.
=C2=A0
But,=C2=A0the docs elsewhere feature a query example show the use of a= wildcard for columns
as well as allowing you to assign names to as many of the leading colu= mns as you wish:
=C2=A0
WITH T0 as ( SELECT 1,2,3 )
SELECT T0.* from T0 as T0(foo,bar) ;
=C2=A0
=C2=A0foo =E2=94=82 bar =E2=94=82 ?column?
=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=C2=A0=C2=A0 1 =E2=94=82=C2=A0=C2=A0 2 =E2=94=82=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 3
(1 row)
=C2=A0
The following curious variant also works:
=C2=A0
WITH T0 as ( SELECT 1,2,3 )
SELECT justAnythingReally.* from T0 as justAnythingReally(foo,bar) ;
=C2=A0
The synoposis/grammer at the top doesn't hint at this either. I= 9;ve checked and this has been supported since at least 9.2 .
=C2=A0

N= either of those examples is:

SELECT * AS "how= would one alias this?" FROM table

So what= 9;s your point?=C2=A0 Obviously you can alias stuff before it makes its way= into a select-list that refers to it using *

In t= his case the FROM clause is what is being alised.=C2=A0 It is documented th= ough I'd need to look to identify the specific location. It=C2=A0would = not be documented in a section regarding the select-list.

David J.
--001a1140faa80eb02405204a6507--