2

I have a database with a lot of tables which contain many columns of type boolean. But my software doesn't support boolean as a datatype. Their support team told me that I should use numeric(1,0) instead of boolean, so I tried:

ALTER TABLE foo ALTER COLUMN bar TYPE numeric(1,0) USING bar::numeric(1,0)

I get an error: can't convert boolean into type numeric.
What can I do to replace the boolean columns with a numeric alternative and preserve the boolean behaviour? Can this numeric(1,0) thing even work?

1 Answer 1

2

you need an extra step - cast to int first:

t=# select true::int::numeric(1,0);
 numeric 
---------
       1
(1 row)

so in your case it would be:

ALTER TABLE foo ALTER COLUMN bar TYPE numeric(1,0) USING bar::int::numeric(1,0)

but frankly saying I believe just converting to int is already enough.

Sign up to request clarification or add additional context in comments.

1 Comment

no, t is boolean or text. in your case obviously it is boolean. int stands for integer and should show 1 or 0...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.