"Jeremy Ford" <jeremford@gmail.com> writes:
> select
> to_char(2009,'9999') as year,
> to_char(3,'09') as month,
> to_date(to_char(2009,'9999')||to_char(3,'99') ,'YYYYMM') as method1,
> to_date(to_char(2009,'9999')||'-'||to_char(3,'09') || '-01','YYYY-MM-DD')
> as method2
Or, eliminating the extraneous stuff, the point is that
regression=# select to_date(' 2009 07', 'YYYYMM');
to_date
------------
0200-09-01
(1 row)
doesn't do what it used to. Ordinarily I might say "well, if you want
leading spaces you need to say that in the format", viz
regression=# select to_date(' 2009 07', ' YYYYMM');
to_date
------------
2009-07-01
(1 row)
However, that just begs the question --- it seems that leading space is
allowed in MM, just not in YYYY. Brendan, is that intentional or is it
a bug?
regards, tom lane