user3750809
user3750809

Reputation:

PostgreSQL lowercase table names

After reading PostgreSQL 9.3 documentation and having run a single simple query to make all column names lowercase I attempted to replicate this to make all the table names all lowercase...

UPDATE pg_attribute SET tablename=lower(tablename);

Unfortunately while the command line PSQL did not throw any errors none of the database table names were made lowercase.

How do I make all the table names lowercase in PostgreSQL?

I don't need anything complex as these are tables that will be dropped as the data is a mess so just a blatantly simple query would be great.

Upvotes: 1

Views: 1751

Answers (1)

zxq9
zxq9

Reputation: 13164

First off, don't do this.

Quote table names instead in the queries you need to run, then "MyTableName" will really be "MyTableName" in your query instead of being folded to lower case before the query is run the way MyTableName => mytablename would be.

If you feel a compelling need to do this -- then you should do it from an SQL dump of the DB

pg_dump > backup.sql
sed -i s/SomeStuff/somestuff/g backup.sql
# ...etc.

If you have a list of table names, play with a big list of sed commands in a sed or shell script so you can tweak things until you've got it right.

That is not just safer, it is less insane hair pulling for you to deal with also. You can blow up the backup data by mistake; no harm done. You can't afford to screw up the data catalogues -- because you'll never get a clean dump again, and a mistake there may not be evident initially, especially if there are stored procedures involved.

Upvotes: 1

Related Questions