On 21 March 2012 11:52, Simon Greener <[email protected]> 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
[email protected]
http://postgis.refractions.net/mailman/listinfo/postgis-users