jwilcox09
jwilcox09

Reputation: 721

Can't cast varchar(255) to float

I am trying to either alter a column type to float or create a new one and copy the contents of the old, but in either case I get:

invalid input syntax for type numeric: "10:59"

I tried

ALTER TABLE videos ALTER COLUMN length TYPE numeric(10,2) USING CAST(length AS numeric(10,2));

I also tried just selecting the value as a float

select length::numeric(10,2) from videos;

but I get the same error. Here is the column description

enter image description here

additionally i when I do

select '10.59'::numeric(10,2), length from videos;

it returns

numeric length
10.59   10:59

Upvotes: 1

Views: 150

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175826

You have values that are not valid. "10:59" cannot be casted to fload.

SELECT '10:59'::float
-- ERROR:  invalid input syntax for type double precision: "10:59"

Please note that your string value contains semicolon: 10:59 != 10.59.

You need to update that value before altering table.

Upvotes: 1

Related Questions