Re: Problem using NULLIF in a CASE expression

Поиск
Список
Период
Сортировка
От Roger Hand
Тема Re: Problem using NULLIF in a CASE expression
Дата
Msg-id DB28E9B548192448A4E8C8A3C1B1E475611CD9@sj1-exch-01.us.corp.kailea.com
обсуждение исходный текст
Ответ на Problem using NULLIF in a CASE expression  (Bruno BAGUETTE <levure@baguette.net>)
Список pgsql-general
Try this:

SELECT CASE
        WHEN btrim(' A string', ' ') = '' OR <field-name> IS NULL
          THEN NULL
        ELSE 6
        END AS type_id;

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org]On Behalf Of Bruno BAGUETTE
Sent: Friday, September 09, 2005 4:45 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] Problem using NULLIF in a CASE expression


Hello,

I have a problem using NULLIF inside a CASE expression.

I explain the goal of my query : I have a table where there is two
fields : one varchar field and one INT8 field.
When the varchar field is empty I have to display the INT8 field.
If the varchar field is not empty I have to display a NULL value (even
if the INT8 field contains something).

BUT : that table is used by several applications and theses applications
does not always store NULL in the varchar field. Some applications store
an empty string '', or stores <space> char(s).
SO, I have to do a btrim and to get a NULL value when I just have ''
after the btrim.

I wrote another (and quite shorter!) SQL query to resume the problem :

SELECT CASE NULLIF(btrim(' A string', ' '), '')
        WHEN NOT NULL
          THEN NULL
        ELSE 6
        END AS type_id;

ERROR:  operator does not exist: text = boolean
HINT:  No operator matches the given name and argument type(s). You may
need to add explicit type casts.

Why this query does not accept the NULLIF ?
What can I do to solve that problem ?

Thanks in advance !

Bruno BAGUETTE.

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

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

Предыдущее
От: Csaba Nagy
Дата:
Сообщение: Re: Problem using NULLIF in a CASE expression
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: Is this a bug or am I doing something wrong?