select count(*) from <empty table>: 0 rows or 1 rows ?

Started by Oleg Bartunovover 26 years ago3 messages
#1Oleg Bartunov
oleg@sai.msu.su

discovery=> select count(*) from publications;
count
-----
0
(1 row)

Does 1 rows is a correct result ?

Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

#2J.M.
darcy@druid.net
In reply to: Oleg Bartunov (#1)
Re: [HACKERS] select count(*) from <empty table>: 0 rows or 1 rows ?

Thus spake Oleg Bartunov

discovery=> select count(*) from publications;
count
-----
0
(1 row)

Does 1 rows is a correct result ?

Absolutely. "SELECT COUNT(*)..." always returns exactly one row (well,
assuming that the table exists, of course) so this is correct. A return
of zero rows would imply that no information was returned but you did
get back information here, the fact that the table is empty.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.
#3Bruce Momjian
maillist@candle.pha.pa.us
In reply to: Oleg Bartunov (#1)
Re: [HACKERS] select count(*) from <empty table>: 0 rows or 1 rows ?

discovery=> select count(*) from publications;
count
-----
0
(1 row)

Does 1 rows is a correct result ?

Oleg

One row is returned, and that row is zero. It is correct.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026