Very useful, Mike, very useful. Thanks
S
On Wed, 21 Mar 2012 10:09:34 +1100, Mike Toews <mwto...@gmail.com> wrote:

On 21 March 2012 11:52, Simon Greener <si...@spatialdbadvisor.com> wrote:
Thanks all for the suggestions.
S

If you are using postgres 9.0 or later, try something like this to
rename tables:

DO $$DECLARE r record;
BEGIN
    FOR r IN (SELECT relname,
                regexp_replace(lower(relname), E'[ \-]+', '_', 'g') AS
new_relname
              FROM pg_class c
              JOIN pg_namespace n ON n.oid=c.relnamespace
              WHERE n.nspname='public' AND relkind='r'
                AND relname <> quote_ident(relname))
    LOOP
        EXECUTE 'ALTER TABLE ' || quote_ident(r.relname) ||
          ' RENAME TO ' || quote_ident(r.new_relname) || ';';
    END LOOP;
END$$

A similar query can be used to rename columns.

-Mike
_______________________________________________
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



--
Holder of "2011 Oracle Spatial Excellence Award for Education and Research."
SpatialDB Advice and Design, Solutions Architecture and Programming,
Oracle Database 10g Administrator Certified Associate; Oracle Database 10g SQL 
Certified Professional
Oracle Spatial, SQL Server, PostGIS, MySQL, ArcSDE, Manifold GIS, FME, Radius 
Topology and Studio Specialist.
39 Cliff View Drive, Allens Rivulet, 7150, Tasmania, Australia.
Website: www.spatialdbadvisor.com
  Email: si...@spatialdbadvisor.com
  Voice: +61 362 396397
Mobile: +61 418 396391
Skype: sggreener
Longitude: 147.20515 (147° 12' 18" E)
Latitude: -43.01530 (43° 00' 55" S)
GeoHash: r22em9r98wg
NAC:W80CK 7SWP3
_______________________________________________
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

Reply via email to