Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    4

    Unanswered: Postgres 7.3 Newbie

    Hello,

    I want to edit the data type of a couple of fields in my DB.
    I have tried the

    Alter table sometable
    Alter column somecolumn varchar(40);


    The docs seems to say it aint supported. Just want to be sure.
    Whats the saftest way of donig this without loosing data or causing corruption..

    Cheers,
    Joyce

  2. #2
    Join Date
    Jan 2003
    Location
    Midwest
    Posts
    138
    It isn't supported yet. You can alter a table to add additional columns, but you can't alter it to modify existing data types. You would need to recreate the table.

  3. #3
    Join Date
    Aug 2003
    Posts
    4
    Originally posted by Memnoch1207
    It isn't supported yet. You can alter a table to add additional columns, but you can't alter it to modify existing data types. You would need to recreate the table.
    Thanks for the confirmation.

  4. #4
    Join Date
    Aug 2003
    Posts
    3
    If you want to change a varchar(n) to a varchar(m) you can do this by poking around in the system data structures. But generally speaking you cannot alter datatypes because how does PG know how to convert 'asdf' to an int?

    So in general yes, rename the old table, create the new, then

    insert into <new>
    select <fields> from <old>

    where you can of course apply any functions you like to your old fields to match the new types.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •