1

I'm converting someone's Microsoft Access database to PHP/PostgreSQL. Referencing all lowercase column names works just fine however the people who created the Access databases "APPARENTLY" "ALWAYS" "SCREAMED" "ALL" "THE" "TIME" "AND" "IT" "MEANS" "HAVING" "TO" "PUT" "QUOTES" "AROUND" "ALL" "COLUMN" "NAMES". I never use capitol letters in column names ever in absolute.

How do I ALTER all the column names so that they have the same names though all lowercase?

There are no same-names/different cases (e.g. there are no column sets like "TableName" and "tableName").

3
  • You could use the information_schema tables to generate the necessary ALTER TABLE ... RENAME COLUMN statements. However, that may piss off the RDBMS if it doesn't like you doing that to columns used in indexes, constraints, keys, views, etc. Honestly, I suggest you just live with it. It's a very minor issue, and not worth breaking things over. Commented Nov 18, 2014 at 19:36
  • @BaconBits Ah no, I'm not living with someone else's inability to code correctly and end up making my code messy though I agree with the approach you suggested; I hadn't thought of that and will try it out. Commented Nov 18, 2014 at 19:44
  • Unfamiliar convention <> inability to code. Commented Nov 18, 2014 at 20:52

1 Answer 1

2

update pg_attribute set attname=lower(attname);

That will make sure there are no upper case letters in any of your tables. You may wish to toss a where clause on there if there are columns that legitimately need an upper case letter.

Sign up to request clarification or add additional context in comments.

1 Comment

UPDATE pg_attribute SET attname=lower(attname); I keep the syntax as all uppercase. Regardless of the letter-casing your query worked for me using psql, thank you!