This is almost same question as Pad arrays with NULL to maximum length for custom aggregate function. the only problem with the answer provided is that function array_fill doesn't exist in Postgres 8.2.
How can I make it useable given the version I have?