| От | Gerardo Herzig |
|---|---|
| Тема | returning count(*) when it is > 1, else -1 |
| Дата | |
| Msg-id | 48F87AD3.6000206@fmed.uba.ar обсуждение исходный текст |
| Ответы |
Re: returning count(*) when it is > 1, else -1
Re: returning count(*) when it is > 1, else -1 |
| Список | pgsql-sql |
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 like select case when (select count(*) from test where id=$1 ) AS total > 0 then total else -1 end; Because i have "Syntax error near AS" I have a plpgsql version of this, but i swear to my boss that it can be done is plain sql. Please tell me that im right :) Thanks! Gerardo
В списке pgsql-sql по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера