Re: Altering a CHAR(4) column CHAR(5) changing pg_attribute - Mailing list pgsql-general

From Tom Lane
Subject Re: Altering a CHAR(4) column CHAR(5) changing pg_attribute
Date
Msg-id 29225.1017163747@sss.pgh.pa.us
Whole thread Raw
In response to Re: Altering a CHAR(4) column CHAR(5) changing pg_attribute  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Responses Re: Altering a CHAR(4) column CHAR(5) changing  (Denis Gasparin <denis@edistar.com>)
List pgsql-general
Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> If you were using varchar, this would be fine. With char, you have
> issues with the padding spaces if you ever convert them to text
> (for example using lower or upper).

But you could do
    update foo set mycol = mycol || '';
after tweaking the atttypmod as Stephan illustrates.  That should force
all the values to the correct length.  (The dummy concatenation is just
to prevent the system from optimizing away the length coercion step.)

            regards, tom lane

pgsql-general by date:

Previous
From: Sonia Sanchez Diaz
Date:
Subject: Performance in subconsult
Next
From: postgresql@fruru.com
Date:
Subject: Re: Performance in subconsult