Re: How to convert a binary filed to an integer field? - Mailing list pgsql-general

From Arjen Nienhuis
Subject Re: How to convert a binary filed to an integer field?
Date
Msg-id AANLkTikkyXRy5F2z9W+mkrkxxjW4=iVPk7eDQQ2rGVhm@mail.gmail.com
Whole thread Raw
In response to Re: How to convert a binary filed to an integer field?  (wei725@lycos.com)
List pgsql-general
Maybe this works:

ALTER TABLE product ALTER status TYPE int USING CASE WHEN status THEN 1 ELSE 0 END;

If it doesn't, can you post the exact SQL you use and the exact error message?

On Mon, Aug 30, 2010 at 5:27 PM, <wei725@lycos.com> wrote:
Unfortunately, the statement doesn't work. I get an error message about unable to convert boolean to integer.

I have a look at the case statement for the conversion, but don't understand how it works.


----- Original Message -----
From: "Arjen Nienhuis" <a.g.nienhuis@gmail.com>
To: wei725@lycos.com
Cc: pgsql-general@postgresql.org
Sent: Thursday, August 26, 2010 4:56:09 AM GMT -08:00 US/Canada Pacific
Subject: Re: [GENERAL] How to convert a binary filed to an integer field?




On Wed, Aug 25, 2010 at 9:29 PM, < wei725@lycos.com > wrote:


I have an application in the product. Now, one status field needs to have three statuses instead of two. How to make a such change in PostgreSQL?



ALTER TABLE product ALTER status TYPE int USING status::integer;


pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Running variable commands from psql
Next
From: wstrzalka
Date:
Subject: Re: Feature proposal