Re: formatting a date when some nulls exist - Mailing list pgsql-novice

From Tom Lane
Subject Re: formatting a date when some nulls exist
Date
Msg-id 28751.1031011720@sss.pgh.pa.us
Whole thread Raw
In response to formatting a date when some nulls exist  (Eric Walstad <eric@walstads.net>)
List pgsql-novice
Eric Walstad <eric@walstads.net> writes:
> I'm trying to format a date type column, which contains some nulls.  I'm
> getting an error:

> ewtest=# select to_char(birthday, 'YYYY-MM-DD') from contacts;
> ERROR:  Unable to convert date to tm

How old is your Postgres??  AFAIR that misbehavior has been gone since
6.5 or so.  Certainly any recent version works:

regression=# create table foo (f1 date);
CREATE TABLE
regression=# insert into foo values('today');
INSERT 288761 1
regression=# insert into foo values(null);
INSERT 288762 1
regression=# select to_char(f1, 'YYYY-MM-DD') from foo;
  to_char
------------
 2002-09-02

(2 rows)

regression=#

            regards, tom lane

pgsql-novice by date:

Previous
From: Eric Walstad
Date:
Subject: formatting a date when some nulls exist
Next
From: Mark Fletcher
Date:
Subject: Dealing with unique IP adresses and ranges