Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have small database with few text fields with "default" collation. I don't want to recreate database. What is the query to alter all problematic fields at once?

To change the single one I can use

ALTER TABLE a_table_name ALTER a_column_name TYPE text COLLATE a_collate;
share|improve this question
You can loop over the columns in a DO block, for example, constructing and executing a dynamic query. – dezso Dec 4 '13 at 15:12

There isn't a single SQL command that will do that for you. You can write a loop in a different language, using the results from

SELECT table_name, column_name
  FROM information_schema.columns
  WHERE table_schema IN ('your_schemas')
    AND data_type = 'text'
    AND collation_name IS NULL;

or similar.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.