How to handle CASE statement with PostgreSQL without need for typecasting

Поиск
Список
Период
Сортировка
От Anthony Hall
Тема How to handle CASE statement with PostgreSQL without need for typecasting
Дата
Msg-id CAFhuWu_vTQr0NSGiKSua8JPfHwGXSH_uQ6bzBWf_bRuKMu3a1g@mail.gmail.com
обсуждение исходный текст
Ответы Re: How to handle CASE statement with PostgreSQL without need for typecasting
Список pgsql-general
Hello,

Trying to find a way to perform a CASE statement without needing to typecast.  Research so far suggests that this is not possible, but I wanted to check with the PSQL community to be sure.


Steps:
1. CREATE TABLE t_update (F1 timestamp(6) NULL )

2. Run statement  UPDATE t_update SET F1 = (CASE WHEN (CURRENT_TIMESTAMP  IS NULL ) THEN (CURRENT_TIMESTAMP ) ELSE (CURRENT_TIMESTAMP ) END)
Result: No exceptions.

3. Run parametrised statement
UPDATE t_update SET F1 = (CASE WHEN (?  IS NULL ) THEN (? ) ELSE (? ) END)

Result: Error
ERROR: VERROR; column "f1" is of type timestamp without time zone but expression is of type text(Hint You will need to rewrite or cast the expression.; Position 27; File d:\pginstaller.auto\postgres.windows-x64\src\backend\parser\parse_target.c; Line 591; Routine transformAssignedExpr; ) (6822148)  


NOTE:  From my research online, I found that typecasting works and also the error from the database suggests typecasting.

This statement works:

UPDATE t_update SET F1 = (CASE WHEN (?::timestamp(6) IS NULL ) THEN (?::timestamp(6) ) ELSE (?::timestamp(6) ) END)   


Please let me know your thoughts.

Many thanks!
Anthony

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

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: DB running out of memory issues after upgrade
Следующее
От: John W Higgins
Дата:
Сообщение: Re: How to handle CASE statement with PostgreSQL without need for typecasting