The pattern 'Day'
is blank-padded to the right, making all days 9 characters long. Use the FM
Template Pattern Modifier to remove any padding:
SELECT d::date AS day
, to_char(d, 'yyyy-mm-dd') AS day_text
, to_char(d, 'FMDay') AS weekday
FROM generate_series('2013-03-01'::date
, '2013-03-07'::date
, interval '1 day') d;
Also demonstrating generate_series()
for timestamps. One less query level.
If you need an actual date
in the view, make it an actual type date
, don't convert to text
and back.
And don't use the basic type name date
as column name. Using day
instead.
And I would just use text
for the text. No point in converting to varchar
.