Re: Converting char to varchar automatically - Mailing list pgsql-general

From Andrus
Subject Re: Converting char to varchar automatically
Date
Msg-id 79ED1A0744DC4A51B2C242E91D58AEED@dell2
Whole thread Raw
In response to Re: Converting char to varchar automatically  (Melvin Davidson <melvin6925@gmail.com>)
Responses Re: Converting char to varchar automatically  (Melvin Davidson <melvin6925@gmail.com>)
List 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 by date:

Previous
From: Sergey Konoplev
Date:
Subject: Re: How to synchronize tables in remote (production) and local databases in case if the structure of local database's table has been modified
Next
From: Melvin Davidson
Date:
Subject: Re: Converting char to varchar automatically