Re: Converting char to varchar automatically

Поиск
Список
Период
Сортировка
От Melvin Davidson
Тема Re: Converting char to varchar automatically
Дата
Msg-id CANu8FixCSgOBSzGcGksS9vC0e+-h8vqg-Xzr4=YM=UQnjE70jA@mail.gmail.com
обсуждение исходный текст
Ответ на Converting char to varchar automatically  ("Andrus" <kobruleht2@hot.ee>)
Ответы Re: Converting char to varchar automatically  ("Andrus" <kobruleht2@hot.ee>)
Re: Converting char to varchar automatically  ("Andrus" <kobruleht2@hot.ee>)
Список pgsql-general
This query might work for you, but double check all result statements first.

SELECT 'ALTER TABLE ' || quote_ident(n.nspname) || '.' ||  quote_ident(c.relname)
       || ' ALTER COLUMN ' || quote_ident(a.attname) || ' TYPE varchar;'
  FROM pg_class c
  JOIN pg_namespace n ON n.oid = c.relnamespace
  JOIN pg_attribute a ON a.attrelid = c.oid
  JOIN pg_type t ON t.oid = a.atttypid
 WHERE t.typname = 'char'
   AND n.nspname <> 'pg_catalog';


On Mon, Oct 6, 2014 at 6:29 AM, Andrus <kobruleht2@hot.ee> wrote:
Database contains about 300 tables.
Most of them contain columns of char(n) type.
 
How to convert all those columns to varchar automatically ?
 
Is it possible to run some update commands in system tables for this ?
Or is it possible to create pgsql script which creates dynamically alter table alter column commands and PERFORMs them ?
 
Any tables have primary keys with char(n) columns and foreign keys on them. Foreign keys are deferrable and initially  immediate.
Will foreign keys allow to perform such alter table alter column commands ?
Or is there better way.
 
Andrus.



--
Melvin Davidson
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.

В списке pgsql-general по дате отправления:

Предыдущее
От: Tim Mickelson
Дата:
Сообщение: Re: Really strange foreign key constraint problem blocking delete
Следующее
От: Richard Frith-Macdonald
Дата:
Сообщение: How to get good performance for very large lists/sets?