Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNJR6-00082X-1Y for pgsql-general@arkaria.postgresql.org; Wed, 01 Feb 2023 20:10:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pNJR4-00032H-VP for pgsql-general@arkaria.postgresql.org; Wed, 01 Feb 2023 20:10:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNJR4-00031x-Kd for pgsql-general@lists.postgresql.org; Wed, 01 Feb 2023 20:10:26 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNJR1-0003ph-UB for pgsql-general@lists.postgresql.org; Wed, 01 Feb 2023 20:10:26 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 311KAL6p1409991; Wed, 1 Feb 2023 15:10:21 -0500 From: Tom Lane To: Ron cc: pgsql-general@lists.postgresql.org Subject: Re: "SELECT FROM foo" acts like "SELECT COUNT(*) FROM foo"? In-reply-to: <3833b34a-a4c1-14ee-fcdc-0fa74baa2cd8@gmail.com> References: <3833b34a-a4c1-14ee-fcdc-0fa74baa2cd8@gmail.com> Comments: In-reply-to Ron message dated "Wed, 01 Feb 2023 14:00:28 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1409989.1675282221.1@sss.pgh.pa.us> Date: Wed, 01 Feb 2023 15:10:21 -0500 Message-ID: <1409990.1675282221@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ron writes: > v12.13 > https://www.postgresql.org/docs/12/sql-select.html > The docs say that one of these are required in the SELECT list. > [ * |/|expression|/ [ [ AS ]/|output_name|/ ] [, ...] ] Really? I don't see anything to that effect in either the syntax synopsis or the text, plus there's this in the Compatibility section: Empty SELECT Lists 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. We probably did say that before 9.4 or so, but if you still find it in modern releases, please say exactly where. > However, *not* mentioning anything also works, though acts like COUNT(*). Well, you get some number of zero-column rows. psql's display of that is a bit idiosyncratic, but nobody's bothered to improve it. regards, tom lane