DROP FUNCTION partial_to_iso_date(INT);
CREATE OR REPLACE FUNCTION partial_to_iso_date(INT) RETURNS TEXT AS $$
SELECT cast($1/10000 as text) || COALESCE('-' || lpad(cast(NULLIF($1/100 % 100,0) as text),2,'0') || COALESCE('-' || lpad(cast(NULLIF($1 % 100, 0) as text),2,'0'), ''), '');
$$ LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT;


