Tuesday, February 12. 2008How to convert a table column to another data typeTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
I had the same problem. It was caused by string default value. So, try first change the default value e.g. to 0 and then convert:
ALTER TABLE ma_tiger ALTER COLUMN fraddl SET DEFAULT 0; ALTER TABLE ma_tiger ALTER COLUMN fraddl TYPE integer;
this is unnecessarily complicated - the default, when casting a char as a integer should be to just give the converted result, not an error msg or a prompt to write a script.
i want to put my column field id in first column of my table.how can i do this in postgresql...can you suggest any queries for clear this problem.....
Thanks in advance
Niya,
Unfortunately this is one of those things you can't do in PostgreSQL to my knowledge. I think there are talks of changing that. So to do this -- 1) you would have to create a new table with the order you want, copy the data from the old table, 2) drop the old table 3) Then rename the new to old name. In practice there isn't much of a reason to have columns ordered a certain way except if you always like seeing your primary keys listed first in design view of the table. When you do a SELECt SELECT column1, column2, .... the column order in the select will be respected. If you are doing SELECT * which will respect the order of the columns in the table, you should get out of the habit of doing that anyway. |
QuicksearchCalendar
CategoriesBlog AdministrationEntry's Links |
||||||||||||||||||||||||||||||||||||||||||