Sometimes the wrong data gets into the database and you have to update the record, that’s no biggie. You run a simple update command and everything is back on track. In other cases the error is not on one record but on many.
Alarm.
I don’t now why exactly, but when I have to do the same thing twice I’m already looking for a way to automate it. So this is what happened.
I added a new domain name to the dns tables dns_soa and dns_rr. This is done through a rails application I’m working on, but the thing I forgot was to check on spaces. So instead of having ‘domainname.com’ in my tables, ‘domainname.com ‘ (an extra space at the end is added) was inserted. The space has to go away and this is how I’ve done it.
First check what you are going to do:
SELECT REPLACE(origin,'domainname ','domainname'), FROM dns_soa WHERE origin like 'domainname %';
Nothing is done to the tables just yet, so be sure to check the result. After carefully checking if that was the result I wanted, I ran the actual update.
UPDATE dns_soa SET origin = REPLACE(origin,'domainname ','domainname') WHERE origin like 'domainname %';