Re: Changing column names in tables 2

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tony Cade <arcade646(at)googlemail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Changing column names in tables 2
Date: 2008-03-05 20:01:12
Message-ID: 20080305200112.GX4755@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tony Cade wrote:

> There are too many fields to issue alter table commands to rename in SQL so
> my question is , is it safe to use a query such as
>
> select relfilenode from pg_class where relname='rates'

> update pg_attribute set attname=lower(attname) where attnum >0 and
> attrelid=nnnn ( from above query)

Don't do that. It's far better to create a shell script, or PL/pgSQL
function, whatever suits you, to get the table/column names from the
catalog and then produce the ALTER TABLE commands you need.

Playing directly with the catalogs is *never* supposed.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-03-05 20:27:45 Re: Requiring a password
Previous Message Tony Cade 2008-03-05 19:32:53 Changing column names in tables 2