Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / argument of CASE/WHEN must be type boolean, not type text / 6 сообщений из 6, страница 1 из 1
19.10.2004, 18:03
    #32745088
jumperFF
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
argument of CASE/WHEN must be type boolean, not type text
Код: plaintext
1.
2.
SELECT f_id, f_stitle, f_title
        CASE WHEN NULLIF(s_title, null) THEN '-test-' END
FROM sales.firm
Пишет
Код: plaintext
ERROR: argument of CASE/WHEN must be type boolean, not type text
Как по мне, то всё правильно, но видимо чего-то нехватает :(
...
Рейтинг: 0 / 0
19.10.2004, 18:05
    #32745094
jumperFF
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
argument of CASE/WHEN must be type boolean, not type text
или даже так
Код: plaintext
1.
SELECT CASE WHEN NULLIF(s_title, null) THEN '-test-' END
FROM sales.firm
...
Рейтинг: 0 / 0
19.10.2004, 18:09
    #32745105
jumperFF
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
argument of CASE/WHEN must be type boolean, not type text
Ага, пробую так и всё получается
Код: plaintext
CASE WHEN s_title IS null THEN '-test-' ELSE s_title END
Но правильно ли это? Что-то в документации это не видно :(
...
Рейтинг: 0 / 0
19.10.2004, 18:48
    #32745208
sibircev
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
argument of CASE/WHEN must be type boolean, not type text
Похоже, что правильно.
В PostgreSQL я давно такое по документации искал, но тоже не видел, а например в Sybase такую конструкцию все кому не лень
...
Рейтинг: 0 / 0
19.10.2004, 19:05
    #32745250
4321
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
argument of CASE/WHEN must be type boolean, not type text
да нет, вроде все черным по белому:
автор
9.12.1. CASE
The SQL CASE expression is a generic conditional expression, similar to if/else statements in other languages:

Код: plaintext
1.
2.
3.
CASE WHEN condition THEN result
     [WHEN ...]
     [ELSE result]
END
CASE clauses can be used wherever an expression is valid. condition is an expression that returns a boolean result. If the result is true then the value of the CASE expression is the result that follows the condition. If the result is false any subsequent WHEN clauses are searched in the same manner. If no WHEN condition is true then the value of the case expression is the result in the ELSE clause. If the ELSE clause is omitted and no condition matches, the result is null.

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
An example: 

SELECT * FROM test;

 a
 --- 
  1 
  2 
  3 


SELECT a,
       CASE WHEN a= 1  THEN 'one'
            WHEN a= 2  THEN 'two'
            ELSE 'other'
       END
    FROM test;

 a | case
 ---+------- 
  1  | one
  2  | two
  3  | other
The data types of all the result expressions must be convertible to a single output type. See Section 10.5 for more detail.

The following "simple" CASE expression is a specialized variant of the general form above:

Код: plaintext
1.
2.
3.
4.
CASE expression
    WHEN value THEN result
    [WHEN ...]
    [ELSE result]
END
The expression is computed and compared to all the value specifications in the WHEN clauses until one is found that is equal. If no match is found, the result in the ELSE clause (or a null value) is returned. This is similar to the switch statement in C.

The example above can be written using the simple CASE syntax:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
SELECT a,
       CASE a WHEN  1  THEN 'one'
              WHEN  2  THEN 'two'
              ELSE 'other'
       END
    FROM test;

 a | case
 ---+------- 
  1  | one
  2  | two
  3  | other
A CASE expression does not evaluate any subexpressions that are not needed to determine the result. For example, this is a possible way of avoiding a division-by-zero failure:

Код: plaintext
SELECT ... WHERE CASE WHEN x <>  0  THEN y/x >  1 . 5  ELSE false END;
...
Рейтинг: 0 / 0
20.10.2004, 16:30
    #32746825
wbear
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
argument of CASE/WHEN must be type boolean, not type text
надо было тип проводить NULLIF(s_title, null)::bool
у постгреса ваще проблеммы с приведением типов ... аналогично:
select '12.05' + 1
не работает

select '12.05'::float + 1
работает
...
Рейтинг: 0 / 0
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / argument of CASE/WHEN must be type boolean, not type text / 6 сообщений из 6, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]