patternsqlMinor
PosgtreSQL - Change multiple fields collation in one query
Viewed 0 times
fieldsqueryonemultiplecollationchangeposgtresql
Problem
I have small database with few text fields with
To change the single one I can use
"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;Solution
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
or similar.
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.
Code Snippets
SELECT table_name, column_name
FROM information_schema.columns
WHERE table_schema IN ('your_schemas')
AND data_type = 'text'
AND collation_name IS NULL;Context
StackExchange Database Administrators Q#54427, answer score: 6
Revisions (0)
No revisions yet.