Re: count syntax - Mailing list pgsql-general

From Tom Lane
Subject Re: count syntax
Date
Msg-id 11375.1050071383@sss.pgh.pa.us
Whole thread Raw
In response to count syntax  (Patrick Welche <prlw1@newn.cam.ac.uk>)
Responses Re: count syntax  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-general
Patrick Welche <prlw1@newn.cam.ac.uk> writes:
> What is the difference between the following?

> transatlantic=# select count(*) from trans;

This is a SQL-spec-mandated special case meaning "count the number of rows".

> transatlantic=# select count(trans.flowindex) from trans;

This counts the number of non-null values of trans.flowindex.  Also
per spec.

> transatlantic=# select count(trans.*) from trans;
ERROR:  Memory exhausted in AllocSetAlloc(204)

This syntax is not legal per SQL spec.  Postgres interprets it as a
command to count the number of non-null values of "trans.*", which in
this context is taken as being a whole-row variable.  Unfortunately the
present implementation of whole-row variables leaks memory ...

I don't believe that a whole-row variable will ever be null, so the
end result is the same as count(*).  You may as well spell it in the
spec-approved fashion.

            regards, tom lane


pgsql-general by date:

Previous
From: Shridhar Daithankar
Date:
Subject: Re: help Request
Next
From: Bruno Wolff III
Date:
Subject: Re: count syntax