Re: Converting char to varchar automatically

Поиск
Список
Период
Сортировка
Искать
От
Andrus
Тема
Re: Converting char to varchar automatically
Дата
Msg-id
E6181F78CA7B4C21AAC815163AFE2789@dell2
Ответ на
Список
Дерево обсуждения
Converting char to varchar automatically "Andrus" <kobruleht2@hot.ee>
Re: Converting char to varchar automatically Andy Colson <andy@squeakycode.net>
How to use record variable with non-null domain in plpgsql "Andrus" <kobruleht2@hot.ee>
Re: How to use record variable with non-null domain in plpgsql Tom Lane <tgl@sss.pgh.pa.us>
How to speed up delete where not in "Andrus" <kobruleht2@hot.ee>
Re: How to speed up delete where not in David Rowley <david.rowley@2ndquadrant.com>
How to drop user if objects depend on it "Andrus" <kobruleht2@hot.ee>
Ynt: How to drop user if objects depend on it Neslisah Demirci <neslisah.demirci@markafoni.com>
Re: Ynt: How to drop user if objects depend on it Jerry Sievers <gsievers19@comcast.net>
Re: How to drop user if objects depend on it Thom Brown <thom@linux.com>
Re: How to drop user if objects depend on it "Andrus" <kobruleht2@hot.ee>
Re: How to drop user if objects depend on it Adrian Klaver <adrian.klaver@aklaver.com>
Re: How to drop user if objects depend on it "Andrus" <kobruleht2@hot.ee>
Re: How to drop user if objects depend on it Tom Lane <tgl@sss.pgh.pa.us>
Re: How to drop user if objects depend on it Tom Lane <tgl@sss.pgh.pa.us>
Re: How to drop user if objects depend on it "Andrus" <kobruleht2@hot.ee>
Re: How to drop user if objects depend on it Tom Lane <tgl@sss.pgh.pa.us>
Re: How to drop user if objects depend on it "Andrus" <kobruleht2@hot.ee>
Re: How to drop user if objects depend on it Tom Lane <tgl@sss.pgh.pa.us>
How to get correct local time "Andrus" <kobruleht2@hot.ee>
Re: How to get correct local time Vitaly Burovoy <vitaly.burovoy@gmail.com>
Re: How to get correct local time Vitaly Burovoy <vitaly.burovoy@gmail.com>
Re: How to get correct local time Adrian Klaver <adrian.klaver@aklaver.com>
How to use row values as function parameters "Andrus" <kobruleht2@hot.ee>
Re: How to use row values as function parameters Adrian Klaver <adrian.klaver@aklaver.com>
Re: How to use row values as function parameters "David G. Johnston" <david.g.johnston@gmail.com>
Re: How to use row values as function parameters "Andrus" <kobruleht2@hot.ee>
Re: How to use row values as function parameters Adrian Klaver <adrian.klaver@aklaver.com>
Re: How to use row values as function parameters "David G. Johnston" <david.g.johnston@gmail.com>
Re: How to drop user if objects depend on it "Andrus" <kobruleht2@hot.ee>
Re: How to drop user if objects depend on it Adrian Klaver <adrian.klaver@aklaver.com>
Re: How to drop user if objects depend on it Melvin Davidson <melvin6925@gmail.com>
Re: How to drop user if objects depend on it "Andrus" <kobruleht2@hot.ee>
Re: How to drop user if objects depend on it Melvin Davidson <melvin6925@gmail.com>
Re: How to drop user if objects depend on it "Andrus" <kobruleht2@hot.ee>
Re: How to drop user if objects depend on it Melvin Davidson <melvin6925@gmail.com>
Re: How to speed up delete where not in Melvin Davidson <melvin6925@gmail.com>
Re: How to use record variable with non-null domain in plpgsql "Andrus" <kobruleht2@hot.ee>
Re: Converting char to varchar automatically Melvin Davidson <melvin6925@gmail.com>
Re: 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 Melvin Davidson <melvin6925@gmail.com>
Re: Converting char to varchar automatically "Andrus" <kobruleht2@hot.ee>
Re: Converting char to varchar automatically Melvin Davidson <melvin6925@gmail.com>
Re: Converting char to varchar automatically "Andrus" <kobruleht2@hot.ee>
Re: Converting char to varchar automatically Jim Nasby <Jim.Nasby@BlueTreble.com>
Re: Converting char to varchar automatically "Andrus" <kobruleht2@hot.ee>
Hi!
 
>There really is no easy way to make a single ALTER for each table unless you use a programming language.
 
I’snt SQL a programming language ?
 
>However, adding a  GROUP BY c.relname,                  a.attname
>would certainly simplify editing. Then you can combine all the
>ALTER COLUMN's for each table.
I wrote
 
with stem as (
SELECT 'ALTER TABLE ' || quote_ident(n.nspname) || '.'
            || quote_ident(c.relname) as prefix ,
  string_agg(
      ' ALTER COLUMN ' || quote_ident(a.attname) || ' TYPE varchar(' || i.character_maximum_length ||')',
      ',' ) as body
  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
group by 1
)
 
select prefix || ' '|| body || ';' as statement
from stem
 
Is this prefect ?
 
Andrus.
В списке pgsql-general по дате отправления
От: Guillaume Lelarge
Дата:
От: Andreas Joseph Krogh
Дата:
FAQ