I have no idea what we're working with, but the Rails framework (I think 
activerecord in particular) could help you here, because it implements 
things like:

DataBase.find_or_create_by_id :id

Which does exactly what you think it does.
-- 
Posted via http://www.ruby-forum.com/.