RE: SELECT INTO question

From: Kevin Brannen <KBrannen(at)efji(dot)com>
To: pgsql-generallists(dot)postgresql(dot)org <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: RE: SELECT INTO question
Date: 2019-07-25 19:52:42
Message-ID: DM6PR19MB34512D4CDC0EBF4D044F405BA4C10@DM6PR19MB3451.namprd19.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----Original Message-----
From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Sent: Thursday, July 25, 2019 2:47 PM
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Kevin Brannen <KBrannen(at)efji(dot)com>; pgsql-generallists.postgresql.org <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: SELECT INTO question

Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com<mailto:adrian(dot)klaver(at)aklaver(dot)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.

Hmm, I don't particularly like that answer as I'd have preferred a "syntax error", but I do understand it.

Thanks for the answer, Adrian; and thanks for the expansion, Tom.

Kevin

This e-mail transmission, and any documents, files or previous e-mail messages attached to it, may contain confidential information. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are hereby notified that any disclosure, distribution, review, copy or use of any of the information contained in or attached to this message is STRICTLY PROHIBITED. If you have received this transmission in error, please immediately notify us by reply e-mail, and destroy the original transmission and its attachments without reading them or saving them to disk. Thank you.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message PegoraroF10 2019-07-25 22:16:25 Re: Too slow to create new schema and their tables, functions, triggers.
Previous Message Tom Lane 2019-07-25 19:47:26 Re: SELECT INTO question