The year is given as int: 2009, 2010 etc.
I want to convert this information to DATE (first January).
My solutions (I prefer the first one):
(year::char || '-01-01')::DATE
'0001-01-01' + ((year-1)::char || ' year')::interval
Is there a better (build in) or more elegant and faster solution?
(I'm currently working with PostgreSQL 8.4 but are also interested in more recent versions.)
to_char()
nor a TINYINT type.'-01-01'
in SQL. Double quotes are reserved for identifiers.