Tom Lane wrote:
> Richard Huxton <[EMAIL PROTECTED]> writes:
>> 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
>
> Actually you could just do
>
> SELECT
> CASE WHEN count(*) >0 THEN count(*) ELSE
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=$
Richard Huxton <[EMAIL PROTECTED]> writes:
> 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
Actually you could just do
SELECT
CASE WHEN count(*) >0 THEN count(*) ELSE -1 END AS total
FROM test WHERE
Στις 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 the
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 t
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
FRO
Hello
2008/10/17 Gerardo Herzig <[EMAIL PROTECTED]>:
> Hi all. Im triyng to implement this in plain sql.
> The only thing i have working is
>
> select case when (select count(*) from test where id=$1 )
>> 0 then (select count(*) from test where id=$1)
>else -1
>end;
>
> But it does a d
Hi all. Im triyng to implement this in plain sql.
The only thing i have working is
select case when (select count(*) from test where id=$1 )
> 0 then (select count(*) from test where id=$1)
else -1
end;
But it does a doble count(*) that i must avoid.
I cant refer to the 'first' count