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

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: returning count(*) when it is > 1, else -1
Дата
Msg-id 48F87E8A.1080103@archonet.com
обсуждение исходный текст
Ответ на returning count(*) when it is > 1, else -1  (Gerardo Herzig <gherzig@fmed.uba.ar>)
Ответы Re: returning count(*) when it is > 1, else -1
Re: returning count(*) when it is > 1, else -1
Список pgsql-sql
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

--  Richard Huxton Archonet Ltd


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Pavel Stehule"
Дата:
Сообщение: Re: returning count(*) when it is > 1, else -1
Следующее
От: Gerardo Herzig
Дата:
Сообщение: Re: returning count(*) when it is > 1, else -1