X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 610F3D1B4F1 for ; Mon, 6 Oct 2003 16:35:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 02527-02 for ; Mon, 6 Oct 2003 13:35:10 -0300 (ADT) Received: from mta06-svc.ntlworld.com (mta06-svc.ntlworld.com [62.253.162.46]) by svr1.postgresql.org (Postfix) with ESMTP id B91DFD1B54F for ; Mon, 6 Oct 2003 13:34:53 -0300 (ADT) Received: from elliott ([81.99.97.206]) by mta06-svc.ntlworld.com (InterMail vM.4.01.03.37 201-229-121-137-20020806) with SMTP id <20031006163450.SQRD12263.mta06-svc.ntlworld.com@elliott> for ; Mon, 6 Oct 2003 17:34:50 +0100 From: "Chris Faulkner" To: "Pgsql-Sql" Subject: create new field Date: Mon, 6 Oct 2003 17:35:11 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/71 X-Sequence-Number: 15471 Hello I would like to change the type of a column. At the moment, it is varchar(4) but I would like it to be int. All values in the field at the moment are actually integer. I tried a way I had seen in the archives - it foes along the lines of adding a column, using update, drop the old column and rename the new one. alter table tab add column new_col int4; update tab set new_col = "OLD_COL"; ERROR: column "new_col" is of type integer but expression is of type characte r You will need to rewrite or cast the expression OK - so I tried casting. template1=# update tab set new_col = "OLD_COL"::int4; ERROR: Cannot cast type character to integer I understand this - some tables might have characters in the varchar but how to get around it in my case ? I know that my character field has only integers in it ? Thanks Chris