Re: NULLIF problem

Поиск
Список
Период
Сортировка
От Erik Jones
Тема Re: NULLIF problem
Дата
Msg-id F0B783FE-5CDA-4B67-99AA-0F0731308D68@myemma.com
обсуждение исходный текст
Ответ на Re: NULLIF problem  (Michael Glaesemann <grzm@seespotcode.net>)
Ответы Re: NULLIF problem
Список pgsql-sql
On Nov 27, 2007, at 8:47 PM, Michael Glaesemann wrote:

>
> On Nov 27, 2007, at 21:04 , Gera Mel Handumon wrote:
>
>> I encounter an error if i use NULLIF with timestamp with time zone.
>> eq. dbtime=nullif(mytime,'')
>>
>> i want to null the value of field DBTIME if the variable mytime=" "
>>
>> DBTIME ="timestamp with time zone" datatype
>>
>> error: column DBTIME is of type timestamp with time zone but
>> expression is of type text.
>
> I believe the reason is that '' is not a valid timestamp value:
> think of it this way:
>
> IF mytime = '' THEN
>   mytime := NULL;
> END IF;
>
> The first thing it needs to do is compare the mytime value with ''.
> As '' is not a valid timestamp value, it may be casing mytime to
> text. You'll run into problems if you're assigning a text value to
> a timestamp field (which happens after the initial comparison--and
> the cast--are done.)
>
> I think you may need to handle this is you middleware, or handle
> the IF THEN explicitly in a function. Maybe CASE would work:
>
> CASE WHEN mytime = '' THEN NULL
>      ELSE CAST(mytime AS TIMESTAMP)
>     END


Why not just:

UPDATE table
SET mytime=NULL
WHERE mytime='';

Erik Jones

Software Developer | Emma®
erik@myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com




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

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: obtaining column names from tables or views
Следующее
От: "Daniel Caune"
Дата:
Сообщение: Re: Strang behaviour SELECT ... LIMIT n FOR UPDATE