Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 3974B1B763E0 for ; Mon, 14 May 2012 00:11:58 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1STlhV-0008Cb-HH for pgsql-sql@postgresql.org; Mon, 14 May 2012 03:11:58 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q4E3Bhw9002251; Sun, 13 May 2012 23:11:44 -0400 (EDT) To: Carlos Mennens cc: =?UTF-8?Q?Viktor_Bojovi=C4=87?= , "PostgreSQL (SQL)" Subject: Re: Finding Max Value in a Row In-reply-to: References: <00ee01cd2fab$1b528b80$51f7a280$@yahoo.com> Comments: In-reply-to Carlos Mennens message dated "Sun, 13 May 2012 22:38:01 -0400" Date: Sun, 13 May 2012 23:11:43 -0400 Message-ID: <2250.1336965103@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/27 X-Sequence-Number: 36575 Carlos Mennens writes: > I'm not understanding why I'm not able to change this column type from > char to integer? > forza=# ALTER TABLE customers > ALTER COLUMN cust_id TYPE integer; > ERROR: column "cust_id" cannot be cast to type integer Try "ALTER ... cust_id TYPE integer USING cust_id::integer". If you don't specify a USING expression, the command requires an implicit coercion from one type to the other, and there is none from char(n) to int. You can force it with an explicit coercion, though. It strikes me that "cannot be cast" is a poor choice of words here, since the types *can* be cast if you try. Would it be better if the message said "cannot be cast implicitly to type foo"? We could also consider a HINT mentioning use of USING. regards, tom lane