Reputation: 2606
Came across this weird behavior today..
select date_part('year', CURRENT_DATE);
2017
select to_char(date_part('year', CURRENT_DATE),'9999');
" 2017"
select length(to_char(date_part('year', CURRENT_DATE),'9999'));
5
Of course I can directly use to_char(CURRENT_DATE,'YYYY')
, but just curious why double precision numbers get a blank space in the beginning when converted into text. Thank you!
Notes:
Upvotes: 1
Views: 209
Reputation: 272567
This behaviour is documented (see the examples table). It's leaving space for a -
sign for negative values.
It seems that you can avoid this with the FM
prefix, i.e. 'FM9999'
.
Upvotes: 1