Changing boolean to a smallint

Started by Christine Pennerover 15 years ago3 messagesgeneral
Jump to latest
#1Christine Penner
chris@fp2.ca

I have a table column I want to change from a boolean to a smallint.
changing false to 0 and true to 1. How do I do that?

Christine Penner
Ingenious Software
250-352-9495
chris@fp2.ca

#2Dean Gibson (DB Administrator)
postgresql@ultimeth.com
In reply to: Christine Penner (#1)
Re: Changing boolean to a smallint

On 2010-11-04 15:41, Christine Penner wrote:

I have a table column I want to change from a boolean to a smallint.
changing false to 0 and true to 1. How do I do that?

Christine Penner
Ingenious Software
250-352-9495
chris@fp2.ca

ALTER TABLE ALTER col_name TYPE SMALLINT
USING CASE WHEN col_name THEN 1 ELSE 0 END;

--
Mail to my list address MUST be sent via the mailing list.
All other mail to my list address will bounce.

#3Dean Gibson (DB Administrator)
postgresql@ultimeth.com
In reply to: Dean Gibson (DB Administrator) (#2)
Re: Changing boolean to a smallint

Oops; see correction below:

On 2010-11-04 16:41, Dean Gibson (DB Administrator) wrote:

On 2010-11-04 15:41, Christine Penner wrote:

I have a table column I want to change from a boolean to a smallint.
changing false to 0 and true to 1. How do I do that?

Christine Penner
Ingenious Software
250-352-9495
chris@fp2.ca

ALTER TABLE table_name ALTER col_name TYPE SMALLINT
USING CASE WHEN col_name THEN 1 ELSE 0 END;

--
Mail to my list address MUST be sent via the mailing list.
All other mail to my list address will bounce.