简体   繁体   English

PostgreSQL小写表名

[英]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... 在阅读了PostgreSQL 9.3文档并运行了一个简单的查询以使所有列名都变为小写之后,我尝试复制该表以使所有表名都变为小写...

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. 不幸的是,尽管命令行PSQL不会引发任何错误,但是没有一个数据库表名被设置为小写。

How do I make all the table names lowercase in PostgreSQL? 如何在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. 我不需要任何复杂的东西,因为这些表会因为数据混乱而被删除,因此仅需简单地进行简单查询就可以了。

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. 在需要运行的查询"MyTableName"引号代替表名,然后在查询中"MyTableName" 实际上就是 "MyTableName" ,而不是像运行MyTableName => mytablename那样在运行查询之前将其折叠为小写。

If you feel a compelling need to do this -- then you should do it from an SQL dump of the DB 如果您迫切需要执行此操作-那么应该从数据库的SQL转储中执行此操作

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. 如果您有一个表名列表,请在sed或shell脚本中使用大量的sed命令,以便您可以进行调整,直到正确为止。

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. 您无须花费太多时间来破坏数据目录,因为您再也不会得到干净的转储,而且最初可能不会出现明显的错误, 尤其是在涉及存储过程的情况下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM