http://archives.postgresql.org/pgsql-general/2007-08/msg00702.php how to implement “replace” in postgres