Skip site navigation (1) Skip section navigation (2)

Re: count(*) of zero rows returns 1

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Cc: David Johnston <polobo(at)yahoo(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: count(*) of zero rows returns 1
Date: 2013-01-15 15:51:11
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com> writes:
> On Mon, Jan 14, 2013 at 4:15 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> David Johnston <polobo(at)yahoo(dot)com> writes:
>>> SELECT *;
>>> Results in:
>>> SQL Error: ERROR:  SELECT * with no tables specified is not valid

> Interesting to note that SELECT * FROM table_with_zero_cols does not
> complain of anything.

Yeah.  IIRC that error check long predates our support for zero-column
tables (which we allowed when we introduced ALTER TABLE DROP COLUMN,
so that dropping the only column doesn't have to be an error case).
You could argue that the existence of zero-column tables makes the
error check inconsistent, but I think it's probably good as-is.  The
possibility that "*" can sometimes validly expand to no columns doesn't
mean that "SELECT *;" isn't almost surely a typo.

			regards, tom lane

In response to

pgsql-hackers by date

Next:From: Peter EisentrautDate: 2013-01-15 15:51:53
Subject: Re: pg_ctl idempotent option
Previous:From: Alvaro HerreraDate: 2013-01-15 15:49:52
Subject: Re: ALTER command reworks

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group