Обсуждение: Converting a timestamp to a date when it contains nulls.
Hi. I'm not sure if the following behaviour is expected or not. Version info: psql (PostgreSQL) 7.0.1 4.0-STABLE FreeBSD 4.0-STABLE #0: Tue Apr 25 18:34:52 EDT 2000 I have a table: create table test (td timestamp); I add a row: insert into test values ('now'); I select from it casting td to a date: select td::date from test; ?column? ------------ 2000-07-23 (1 row) Everything is peachy. Now I insert a NULL: insert into test values (NULL); Everything is no longer peachy. select td::date from test; ERROR: Unable to convert null timestamp to date Shouldn't all casts be able to handle the case where it is NULL? -Michael
"Michael Richards" <michael@fastmail.ca> writes: > Shouldn't all casts be able to handle the case where it is NULL? Yup, it's a bug. It's fixed in current sources. regards, tom lane
> "Michael Richards" <michael@fastmail.ca> writes: >> Shouldn't all casts be able to handle the case where it is NULL? > > Yup, it's a bug. It's fixed in current sources. Is there a patch available that I can apply to the 7.0.2 source to fix the problem? Or is there going to be a 7.0.3 that I should wait for? -Michael
"Michael Richards" <michael@fastmail.ca> writes: >>> Shouldn't all casts be able to handle the case where it is NULL? >> >> Yup, it's a bug. It's fixed in current sources. > Is there a patch available that I can apply to the 7.0.2 source to > fix the problem? Or is there going to be a 7.0.3 that I should wait > for? Just look for the place where the error is being spit out (somewhere in backend/utils/adt/) and change the "elog(ERROR, ...)" call into "return NULL". Should work, but I haven't tried it in 7.0. regards, tom lane