Re: Converting char to varchar automatically

Поиск
Список
Период
Сортировка
От Andrus
Тема Re: Converting char to varchar automatically
Дата
Msg-id 79ED1A0744DC4A51B2C242E91D58AEED@dell2
обсуждение исходный текст
Ответ на Re: Converting char to varchar automatically  (Melvin Davidson <melvin6925@gmail.com>)
Ответы Re: Converting char to varchar automatically  (Melvin Davidson <melvin6925@gmail.com>)
Список pgsql-general
Hi!
 
Thank you.
 
>This revised query should give you what you need:
>SELECT 'ALTER TABLE ' || quote_ident(n.nspname) || '.'
>            || quote_ident(c.relname)
>            || ' ALTER COLUMN ' || quote_ident(a.attname) || ' TYPE varchar(' || i.character_maximum_length || ');'
>  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
>    JOIN information_schema.columns i ON (i.table_name = c.relname AND i.column_name = a.attname)
>WHERE t.typname = 'bpchar'
>   AND c.relkind = 'r'
>   AND n.nspname <> 'pg_catalog' and not attisdropped;

How to create single alter table command for every table ?
Can we use string concat aggregate function or window functions or plpgsql or something other ?
 
Andrus.

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

Предыдущее
От: Sergey Konoplev
Дата:
Сообщение: Re: How to synchronize tables in remote (production) and local databases in case if the structure of local database's table has been modified
Следующее
От: Melvin Davidson
Дата:
Сообщение: Re: Converting char to varchar automatically