Select CASE when null ?

Поиск
Список
Период
Сортировка
От Camilo Sperberg
Тема Select CASE when null ?
Дата
Msg-id f05190a90901141248x59064e8qf17bf3431a58304f@mail.gmail.com
обсуждение исходный текст
Ответ на Select CASE when null ?  ("Camilo Sperberg" <unreal4u@chilehardware.com>)
Список pgsql-general
Hi list :) How are you today?

Being fast: I have the following table with the following data in it:

users:
mid --- id_group --- username
1 -----    2     --- test
2 -----    2     --- blabla
3 -----    4     --- etcetc

and the following select:

SELECT
  CASE mid WHEN NULL THEN CAST(0 AS integer) 
           ELSE mid
  END AS mid,
  CASE id_group WHEN NULL THEN CAST(0 AS integer)
                ELSE id_group
  END AS id_group
FROM users
WHERE username = 'test';

This query returns:
mid --- id_group
1   ---    2

Now, what I want is when the user isn't found, (aka WHERE username isn't found) it should return me this:

mid --- id_group
0   ---    0

But it returns 0 rows...

I've tried so far with
CASE mid WHEN NOT FOUND -> ERROR: column "found" does not exist
CASE mid WHEN NOT EXISTS -> ERROR: column "exists" does not exist
and other variations, however, I haven't be able to accomplish this, the idea is that it should always return at least 1 row...


I know it must be a some kind of small stupidity, but after 2 hours googling and trying, i seriously thought of asking it to the list...

Thanks in advance ;)

Greetings, Camilo Sperberg

--
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www: http://www.chw.net/

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

Предыдущее
От: Bill Moran
Дата:
Сообщение: pgdiff equiv
Следующее
От: Mark Styles
Дата:
Сообщение: Re: Select CASE when null ?