Search Postgresql Archives

Re: COUNT() with ORDER BY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 14 jan, 17:02, "Andrus" <kobrule...@xxxxxx> wrote:
> create temp table test (col char);
> select count(col) from test order by col;
>
> causes
>
> ERROR:  column "test.col" must appear in the GROUP BY clause or be used in
> an aggregate function
> SQL state: 42803
>
> How to fix this ?
> This statement is generated by DbLinq driver and it is difficult to re-qrite
> the driver.
>
> Query looks quite resonable to me and should be accepted by PostgreSQL 8.3
> Beta.
>
> Andrus.

Give a name to the count column and create a subquery:

select	*
from	(
	select	count(col) as count_col
	from	test
	) subquery_tmp_name_as_you_wish
order by count_col;

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux