upsert using plpgsql