In a previous post:
“Another short post. Got self intersecting geometries? Want to fix them inside PostGIS? Me too. Fortunately, someone has already written the code, so you and I don’t have to:
http://linfiniti.com/2010/07/cleaning-geometries-inside-postgis/
Now, let’s see how long it takes to run on my 760,000 record landcover table… .”
As usual, there’s a better way. With PostGIS 2.0, you can (will be able to) use ST_MakeValid. As a (soon to be) native function, it should be pretty fast. See Paul Ramsey’s FOSS4G presentation: http://s3.opengeo.org/postgis-power.pdf