Skip site navigation (1) Skip section navigation (2)

Re: Backend dies upon UPDATE of DATE field with CASE WHEN, 6.5.3

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Emils Klotins" <emils(at)mail(dot)usis(dot)bkc(dot)lv>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Backend dies upon UPDATE of DATE field with CASE WHEN, 6.5.3
Date: 1999-11-29 16:18:32
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugs
"Emils Klotins" <emils(at)mail(dot)usis(dot)bkc(dot)lv> writes:
> 3. If I try the following update in the psql monitor:

> UPDATE authors set firstname='dasd',
> lastname='asdadasd', 
> birthdate=(CASE WHEN (text '12-12-1956')=(text '') THEN 
> NULL ELSE '12-12-1956' END), 
> birthplace='asdasd',commentary='', 
> lastname_original='asdasd', firstname_original='asdfg', 
> birthplace_original='' WHERE author_id=56

Small correction for anyone else trying to reproduce this problem ---
use WHERE author_id=55, or another author_id that is in the given data.

> I get UPDATE 1, however, on all subsequent UPDATEs for that 
> row, backend dies with the following error message.

Yes, I see it in 6.5.3.  In current sources I get

ERROR:  There is no function 'date' with argument #0 of type UNKNOWN

which suggests that the problem is rooted in mis-type-assignment of
the CASE expression.  Since you have a NULL and an untyped string
constant as the two possible values of the CASE, it's not too surprising
that the system has some difficulty in figuring out what datatype the
CASE will yield :-(.  Presumably this is resulting in bogus data getting
stored into the birthdate field.

I will see to it that this works better in 7.0, but the fix may be too
complex to back-patch into 6.5.3, and I don't have it right now anyway.
As a workaround, try forcing the non-null side of the CASE to be cast
to the right datatype:

birthdate=(CASE WHEN (text '12-12-1956')=(text '') THEN 
NULL ELSE '12-12-1956'::date END),

This seemed to make the problem go away for me.

			regards, tom lane

pgsql-bugs by date

Next:From: Emils KlotinsDate: 1999-11-29 17:33:10
Subject: Backend dies upon UPDATE of DATE field with CASE WHEN, 6.5.3
Previous:From: Denis N. StepanovDate: 1999-11-28 16:39:01
Subject: Bug report

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group