We're Moving!

The Vertica Forum is moving to a new OpenText Analytics Database (Vertica) Community.

Join us there to post discussion topics, learn about

product releases, share tips, access the blog, and much more.

Create My New Community Account Now


Type safe coercion — Vertica Forum

Type safe coercion

edited 2:08AM in General Discussion

What error-tolerant type coercion operators / functions exist?
I thought ::! would yield either 3 or null but it throws an error.
Use case is loading real world data into legacy tables for many columns with a consistent simple operator, not wanting to think too specifically about each particular column type, target type, and conversion path.

SELECT '3.14' ;  `'3.14'`
SELECT '3.14' :: FLOAT ;  `3.14`
SELECT '3.14' :: INT  ;  ` Invalid input syntax for integer: "3.14" `
SELECT '3.14' ::! INT  ;  `Invalid input syntax for integer: "3.14" `
SELECT '3.14' !:: INT  ;  `7` (this was a fun one to figure out)
SELECT CAST('3.14' AS INT);  `Invalid input syntax for integer: "3.14"`
SELECT '3.14' :: FLOAT :: INT ; `3`
SELECT ROUND( '3.14') ; `3`

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file