Skip site navigation (1) Skip section navigation (2)

Re: convert char to varchar

From: "Peter Koczan" <pjkoczan(at)gmail(dot)com>
To: "Kostis Mentzelos" <mentzelos(at)gmx(dot)net>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: convert char to varchar
Date: 2007-10-18 15:37:10
Message-ID: 4544e0330710180837ya0a7082v2db9fbbe0119bb9f@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-admin
On 10/18/07, Peter Koczan <pjkoczan(at)gmail(dot)com> wrote:
> > Is there any other way to clear trailing spaces when I restore the table?
>
> If you're running 8.x, you can do this in place:
>
> ALTER TABLE c1 ALTER COLUMN name varchar(20) USING rtrim(name), ALTER
> COLUMN date varchar(20) USING rtrim(date);
>
> This could take a long time if the table is large or has a lot of indexes on it.

Oops. The command should be:

ALTER TABLE c1 ALTER COLUMN name TYPE varchar(20) USING rtrim(name),
ALTER COLUMN date TYPE varchar(20) USING rtrim(date);

I forgot the TYPE keyword...it's important.

Peter

In response to

pgsql-admin by date

Next:From: Alvaro HerreraDate: 2007-10-18 16:25:37
Subject: Re: could not open file "global/pg_database"
Previous:From: Peter KoczanDate: 2007-10-18 15:35:40
Subject: Re: convert char to varchar

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group