Re: count syntax

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Patrick Welche <prlw1(at)newn(dot)cam(dot)ac(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: count syntax
Date: 2003-04-11 14:29:43
Message-ID: 11375.1050071383@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Patrick Welche <prlw1(at)newn(dot)cam(dot)ac(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2003-04-11 14:33:53 Re: count syntax
Previous Message Ken Guest 2003-04-11 14:18:57 Re: help Request