Re: Altering a (populated) database column

Oleg Broytman <[email protected]> Tue, 24 Oct 2017 22:33:35 +0200
Newsgroups gmane.comp.python.sqlobject
Message-ID <[email protected]>
On Tue, Oct 24, 2017 at 09:16:57PM +0100, Hugo Mills <[email protected]> wrote:
>    Hi, Oleg,
>    Thanks for the prompt reply.

   Welcome!

> On Tue, Oct 24, 2017 at 09:37:57PM +0200, Oleg Broytman wrote:
> > On Tue, Oct 24, 2017 at 08:00:13PM +0100, Hugo Mills <[email protected]> wrote:
> > >    Is there any way that I can modify an existing database column,
> > > with data in it, without losing the data in it? All I need to be able
> > > to do is increase the size of a StringCol.
> > > 
> > >    I can see addColumn and delColumn methods of the sqlmeta object,
> > > but not an alterColumn or anything similar.
> > 
> >    Probably yes (depends on the backend) but not with SQLObject.
> > SQLObject can CREATE/DROP tables, columns and indices but cannot ALTER
> > them.
> >    You need to execute ALTER TABLE connecting directly or call
> > connection.execute("ALTER TABLE ...")
> > 
> >    What us your backend? MySQL?
> 
>    It's Postgres. If there's no other way than connection.execute(),

   Example: extend a column to 255 characters:

   ALTER TABLE tableName ALTER COLUMN columnName TYPE varchar(255);

> then I've got no real problem with working that out. I was just hoping
> that there was a less... raw approach.

   Alas!

>    Hugo.
> 

Oleg.
-- 
     Oleg Broytman            http://phdru.name/            [email protected]
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot