pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: "SELECT FROM foo" acts like "SELECT COUNT(*) FROM foo"?
Date: Wed, 1 Feb 2023 14:00:28 -0600
Message-ID: <3833b34a-a4c1-14ee-fcdc-0fa74baa2cd8@gmail.com> (raw)

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|/  ] [, ...] ]

However, *not* mentioning anything also works, though acts like COUNT(*).

test=# select * from sales_detail;
  cust_id |        order_ts         | seq_no | inventory_id | quantity | 
price  | tax_rate
---------+-------------------------+--------+--------------+----------+--------+----------
        1 | 2020-01-05 13:05:42.567 |      1 |        12345 | 5.80 |  28.40 
|    0.092
        1 | 2020-01-05 13:05:42.567 |      2 |        23456 | 6.00 |  98.40 
|    0.092
        1 | 2020-01-05 13:05:42.567 |      3 |        34567 | 1.80 |  67.00 
|    0.092
        1 | 2020-01-05 13:05:42.567 |      4 |        45678 | 450.00 |   
2.00 |    0.092
        1 | 2020-02-05 13:05:42.567 |      1 |         6575 | 5.20 | 567.00 
|    0.045
        1 | 2020-02-05 13:05:42.567 |      2 |         4565 | 456.00 | 
545.00 |    0.045
        1 | 2020-02-05 13:05:42.567 |      3 |         7899 | 768.00 | 
432.00 |    0.045
        1 | 2020-02-05 13:05:42.567 |      4 |         2354 | 556.00 | 
890.00 |    0.045
        1 | 2020-03-05 13:05:42.567 |      1 |         6575 | 5.20 | 567.00 
|    0.045
        1 | 2020-03-05 13:05:42.567 |      2 |         4565 | 456.00 | 
545.00 |    0.045
        1 | 2020-03-05 13:05:42.567 |      3 |         7899 | 768.00 | 
432.00 |    0.045
(11 rows)

test=#
test=# select  from sales_detail;
--
(11 rows)

Is it interpreting the lack of column names, expressions or "*" as a null 
expression?

We only noticed this when someone forgot to put an asterisk in a psql query 
and thought something was broken.  We expected psql to throw a syntax error...

-- 
Born in Arizona, moved to Babylonia.

view thread (5+ messages)  latest in thread

Message-ID: <3833b34a-a4c1-14ee-fcdc-0fa74baa2cd8@gmail.com>
Permalink:  ../3833b34a-a4c1-14ee-fcdc-0fa74baa2cd8@gmail.com/
Also on:    postgresql.org/message-id/3833b34a-a4c1-14ee-fcdc-0fa74baa2cd8@gmail.com

 · 

reply

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: ronljohnsonjr@gmail.com
  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>

* 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