From: Tom Lane <tgl@sss.pgh.pa.us>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Kevin Brannen <KBrannen@efji.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: SELECT INTO question
Date: Thu, 25 Jul 2019 15:47:26 -0400
Message-ID: <31985.1564084046@sss.pgh.pa.us> (raw)
In-Reply-To: <c781b965-5e01-8072-377a-40b24001f64c@aklaver.com>
References: <DM6PR19MB34512BA38FA95EEC830CB68BA4C10@DM6PR19MB3451.namprd19.prod.outlook.com>
<c781b965-5e01-8072-377a-40b24001f64c@aklaver.com>
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 7/25/19 12:23 PM, Kevin Brannen wrote:
>> We're trying to understand what happened with a SELECT INTO. The problem
>> can be see with this example:
>>
>> nms=# select into t2 from t1;
>> SELECT 5
>> # select * from t2;
>> --
>> (5 rows)
> The list of output expressions after SELECT can be empty, producing a
> zero-column result table. This is not valid syntax according to the SQL
> standard. PostgreSQL allows it to be consistent with allowing
> zero-column tables. However, an empty list is not allowed when DISTINCT
> is used.
Right, you selected no columns from t1, so t2 has no columns (and yet
five rows). Worth noting here is that psql is a bit squirrely about
displaying zero-column results --- it drops the column-names header
line, and it doesn't emit a blank-line-per-row as one might expect.
Perhaps somebody ought to fix that, but it's such a corner case that
no one has bothered yet.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, adrian.klaver@aklaver.com, KBrannen@efji.com
Subject: Re: SELECT INTO question
In-Reply-To: <31985.1564084046@sss.pgh.pa.us>
References: <DM6PR19MB34512BA38FA95EEC830CB68BA4C10@DM6PR19MB3451.namprd19.prod.outlook.com> <c781b965-5e01-8072-377a-40b24001f64c@aklaver.com> <31985.1564084046@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox