On Fri, May 11, 2012 at 4:42 PM, Viktor Bojović
<viktor.bojovic@gmail.com> wrote:
> you can convert from type to type using ::varchar or ::char(size) or
> ::integer
> so you can use sequence but you will have to convert it's result to suitable
> type (that can also be put in default value of user_id attribute)
I'm not understanding why I'm not able to change this column type from
char to integer? There are no non-numeric existing characters stored
in this particular column (cust_id). I've gone so far as to delete the
foreign key and primary key that associated with this column (cust_id)
but still I get a generic error:
forza=# \d customers Table "public.customers" Column | Type | Modifiers
--------------+------------------------+-----------cust_id | character(10) |cust_name | character
varying(100)| not nullcust_address | character(50) |cust_city | character(50) |cust_state |
character(5) |cust_zip | character(10) |cust_country | character(50) |cust_contact |
character(50) |cust_email | character(255) |
All the values in the column in question:
forza=# SELECT cust_id
forza-# FROM customers
forza-# ORDER BY cust_id; cust_id
------------1000110002100031000410005
(5 rows)
forza=# ALTER TABLE customers
ALTER COLUMN cust_id TYPE integer;
ERROR: column "cust_id" cannot be cast to type integer
When I view the logs in /var/log/postgresql.log, I see the same exact
error printed above so I can only assume the problem is invalid SQL
statement or I'm breaking some ANSI SQL rule. Can someone please help
me understand how I can change the data type for this column? I've
deleted the primary key constraint so I don't know if that was a good
/ bad idea. Thanks for any info / help!
-Carlos