Skip to content Skip to sidebar Skip to footer

Cannot Cast Type Numeric To Boolean

ALTER TABLE products ALTER COLUMN power_price DROP DEFAULT; ALTER TABLE products ALTER COLUMN power_price TYPE bool USING (power_price::boolean); ALTER TABLE products ALTER COLUMN

Solution 1:

Use:

ALTERTABLE products ALTER power_price TYPE bool USING (power_price::int::bool);

There is no direct cast defined between numeric and boolean. You can use integer as middle-ground. text would be another candidate for middle ground, since every type can be cast from / to text. Values have to be 1 / 0 of course.

Better yet, do it all in a single command for better performance and shorter lock time:

ALTERTABLE products
  ALTER power_price DROPDEFAULT
 ,ALTER power_price TYPE bool USING (power_price::int::bool)
 ,ALTER power_price SETNOTNULL
 ,ALTER power_price SETDEFAULTfalse;

Details in the manual about ALTER TABLE.

Post a Comment for "Cannot Cast Type Numeric To Boolean"