Re: returning count(*) when it is > 1, else -1 - Mailing list pgsql-sql

From Achilleas Mantzios
Subject Re: returning count(*) when it is > 1, else -1
Date
Msg-id 200810171529.00514.achill@matrix.gatewaynet.com
Whole thread Raw
In response to Re: returning count(*) when it is > 1, else -1  (Gerardo Herzig <gherzig@fmed.uba.ar>)
Responses Re: returning count(*) when it is > 1, else -1
List pgsql-sql
Στις Friday 17 October 2008 15:11:10 ο/η Gerardo Herzig έγραψε:
> Richard Huxton wrote:
> > Gerardo Herzig wrote:
> >> But it does a doble count(*) that i must avoid.
> >> I cant refer to the 'first' count like
> >> select case when (select count(*) from test where id=$1 ) AS total
> >>     > 0 then total
> >>     else -1
> >>     end;
> >
> > SELECT
> >   CASE WHEN total >0 THEN total ELSE -1 END AS new_total
> > FROM (
> >   SELECT count(*) AS total FROM test WHERE id=$1
> > ) AS raw_total
> >
> Pavel, Richard, you got it dudes! I have to say, that kinda 'reference
> before assingment' of "total" doesnt look logical to me.
>

Then, both you and your boss need some SQL courses :) (no offense)

> Thanks again!!
> Gerardo
>



--
Achilleas Mantzios


pgsql-sql by date:

Previous
From: Gerardo Herzig
Date:
Subject: Re: returning count(*) when it is > 1, else -1
Next
From: Tom Lane
Date:
Subject: Re: returning count(*) when it is > 1, else -1