on 2015 Dec 14 2:51 PM
We have a database with the original table and column names created in all UPPER CASE (influenced from back in the day when one of those other databases had to have upper case names...). I would like to clean it up by changing all these to lower case (much more readable, and consistent with all the newer tables).
But an ALTER...RENAME tells me the table or column already exists.
It feels pretty scary to rename to a slighlty different name and then back to the original in lowercase... what underlying and undetectable effects will this have...
Is there a safe way?
Thanks, Bill
Request clarification before answering.
So, sounds like I haven't missed anything obvious. I guess my plan wll be: 1. Do an UNLOAD 2. Write a Stored Proc to use the catalog tables to pickup the uppercase names and then REPLACE the values in the script file. 3. Do the RELOAD.
And... get a nice tidy defragged database file in the process.
The DB is only 8GB in size, and we have a substantial server, so not really a big deal.
Thanks Volker and Mark.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
FWIW: You may be able to easily update the reload.sql script using a perl script similar to:
#!perl -n s/^CREATE (.*\\s)?TABLE "([^"]+)"\\."([^"]+)"/'CREATE '.$1.'TABLE "'.$2.'"."'.lc($3).'"'/se; print;
If you were to name the above script file 'lc_table_names.pl' then you would run:
perl lc_table_names.pl reload.sql > reload_lc.sql
PERL script... should that be spelled PEARL? grn
I remember Breck writing years ago about people who own a hammer always use a hammer to solve every problem. That would be me: I know PowerBuilder and SQLA very well, and have ignored all other languages as a distraction. So I only have 2 hammers in my toolkit.
Now, the inevitable xkcd link...
> should that be spelled PEARL?
No, purl...
So you are basically asking for a REGEXP_REPLACE SQL function in order to have something more - though not necessarily something "much more readable":) - in the familiar toolkit?
Well, I guess I had forgot to add another ":)" to my only partially serious suggestion...
s/^CREATE (.*\\s)?TABLE "([^"]+)"."([^"]+)"/'CREATE '.$1.'TABLE "'.$2.'"."'.lc($3).'"'/se;
is not a regex I would claim to understand and certainly not one I could come up with myself...
That being said, for other (and simpler) use cases I would like to have a REGEXP_REPLACE(): If you can find patterns with REGEXP_SUBSTR(), it's sometimes unsatisfying if you cannot change them...
User | Count |
---|---|
62 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.