Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 1D84D1E0AD71 for ; Wed, 11 Jan 2012 20:20:58 -0400 (AST) Received: from smtp108.prem.mail.sp1.yahoo.com ([98.136.44.63]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Rl8PW-0008W8-Su for pgsql-sql@postgresql.org; Thu, 12 Jan 2012 00:20:57 +0000 Received: (qmail 63543 invoked from network); 12 Jan 2012 00:14:01 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=ddTH4pINluDTJXVVQYy2O/rJ59+UlK011nMsD9x6LeHuGLgJIkAU4QjePcUvawtO+Og0HsFZkHa2g2EuR4oAN6AWtAdmYHEq8cm2hCLrM/loW9gYTYfBNaXhsPGm/GIxd9exLptjvl32JbaT6pHAkcUb9uD6vSLMaAbjSU0KWMo= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1326327241; bh=mZZkDhPd7upSa0+cWlYcfpYsHftxB+AeZc/1y1iqnqY=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=rrYD2CGMOjzHYZZKoxXx64l0MJsh451Eyl4cYIBPwyk6ZIB3BaIYRkrWlLPODPam8LIpUCnqDadEo3olNzyd7De7eSv1Nz9D8u1YHsgne4YhptLUkzFqpS/Wt9jU2LJVcN/5IVPDKZsiWYdlvylmFF/WbJmfsLGVkLpsxaTtcnM= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: iiZvEr4VM1n1IHYXCutG0pVGNeVO4xgVPaSbpYX_oY9xaqv E6kjkqrhVvHzWNFfEycnhjeOMBROiPVJcrhhyccXhOqcpbFLZYa9UdYj0_GP yc9ePDtCRI_alXRwsydmH7FLbOtHsP9xVQQarrVer79fT9iWA4Ez2z4.t4IR 2CK3OljC5QLVsd0yc.e8BhzijsdeRz7wUrhlDoKofE6QPU3HdidvrjOI0eBA QmXnZcdmV4EOEQsq4nNEUz23xwhdzx2C0egIb_5KjmyOeqjmgDZoSiYEHObk v3f2eOwW8R2CQdqh4AqdLbORtLkg19apoow7Pg3uI.aft1r.MLHM9qqspSyW AOkgOfizfeUxZYEg03KxGbuXMf9Hk4MWAkRePFJW.iLfLmJFskPHJt6wnVHZ PpULaQQ-- X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.23.188 with login) by smtp108.prem.mail.sp1.yahoo.com with SMTP; 11 Jan 2012 16:14:01 -0800 PST From: "David Johnston" To: "'Carlos Mennens'" , "'PostgreSQL \(SQL\)'" References: In-Reply-To: Subject: Re: Unable To Alter Data Type Date: Wed, 11 Jan 2012 19:13:55 -0500 Message-ID: <00be01ccd0bf$1340da50$39c28ef0$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQGNcztqmUMBRmK1S6EAlHM9b0Mba5aGkj5A Content-Language: en-us X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201201/42 X-Sequence-Number: 36213 -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Carlos Mennens Sent: Wednesday, January 11, 2012 6:53 PM To: PostgreSQL (SQL) Subject: [SQL] Unable To Alter Data Type Now I'm attempting to ALTER the field 'cust_zip' TYPE from character to integer however I'm getting the following error: ---------------------------------------------------------------------------- -------- I think there is a rule in PostgreSQL that says that any field with "zip" in the name MUST BE of a character type :) You seriously do not want to turn this into an integer (big or otherwise) - ZIP (POSTAL) CODES ARE NOT NUMERIC; THEY ARE TEXT! If someone is telling you to make this change then tell them they are wrong and whatever requirement are in place on the other end need to be modified - not the table you indicate. I do confirm, however, that a direct cast from character to bigint works and thus you SHOULD be able to perform the TYPE alteration without adding the USING (expression) clause. So either this is a bug OR, more likely, character-to-bigint casting is not implicit (or an assignment cast, whatever that is) and so you must resort to the USING clause - which does work. [ ... ALTER COLUMN zip_code TYPE bigint USING (zip_code::bigint) ] http://www.postgresql.org/docs/9.0/interactive/sql-altertable.html This is on 9.0 for me. However, I will say again, you DO NOT WANT TO ACTUALLY DO THIS! The specific issue is that some US Postal Code begin with a zero ( 0 ) and so whenever you want to the zip_code value you need to pad leading zeros if the length is less than 5. Now consider that a full zip_code can be in 5+4 format with an embedded hyphen and you no longer can even store it as numeric. If you deal with Canada (and maybe Mexico) at all then spaces and letters become acceptable characters within the zip_code. David J.