Обсуждение: Altering Column Date Types

Поиск
Список
Период
Сортировка

Altering Column Date Types

От
Desmond Coughlan
Дата:
Hi,
I can't find anything in the docs about this.  I want to alter a column in
a table, which is currently an INTEGER, in order that it be FLOAT.

family=# \d debtors
            Table "debtors"
   Column    |     Type      | Modifiers
-------------+---------------+-----------
 first_name  | character(15) |
 second_name | character(15) |
 how_much    | integer       |
 city        | character(10) |
 country     | character(2)  |

Is this possible ?  All that I can see, are changing column names, changing
their defaults (if any), but not to change the data type.

Thanks.

D.

--
Desmond Coughlan          |'Io non mori, e non rimasi vivo'
desmond@zeouane.org
http://www.zeouane.org

Вложения

Re: Altering Column Date Types

От
Aarni Ruuhimäki
Дата:
Hi Desmond !


I use 'pg_dump -c my_db > my_db_dump' and then edit the dump file's CREATE
TABLE statements to change column data-tytes. When done, read or re-create
the db back in with 'cat my_db_dump | psql my_db'


Just make sure your data fits into the new data-type.


BR,


Aarni


Re: Altering Column Date Types

От
"Chris Boget"
Дата:
> I use 'pg_dump -c my_db > my_db_dump' and then edit the dump file's CREATE
> TABLE statements to change column data-tytes. When done, read or re-create
> the db back in with 'cat my_db_dump | psql my_db'
> Just make sure your data fits into the new data-type.

The only thing that may be problematic with this method is if the table being dumped
has some foreign key constraints on it from other tables.  So to add on to the above
steps, before you dump (or some time before you recreate the table), drop the other
constraints, do the above then recreate the other constraints.
Pain in the butt, yes, but unless you do this you won't be able to drop the table in
the first place.

Chris