Re: returning count(*) when it is > 1, else -1

From: Gerardo Herzig <gherzig(at)fmed(dot)uba(dot)ar>
To: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, Richard Huxton <dev(at)archonet(dot)com>, pavel(dot)stehule(at)gmail(dot)com
Subject: Re: returning count(*) when it is > 1, else -1
Date: 2008-10-17 12:27:15
Message-ID: 48F884A3.6060900@fmed.uba.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Achilleas Mantzios wrote:
> Στις 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)
>
Hahaha none taken dude, youre absolutely right.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleas Mantzios 2008-10-17 12:28:59 Re: returning count(*) when it is > 1, else -1
Previous Message Gerardo Herzig 2008-10-17 12:11:10 Re: returning count(*) when it is > 1, else -1