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


Is there a way to test if a varchar is cast-able into a int before casting it? — Vertica Forum

Is there a way to test if a varchar is cast-able into a int before casting it?

Is there a way to test if a varchar is cast-able into a int before casting it? select (int '3'); works. But I don't know what values I will be getting; I just know that they are supposed to be integers. What I need is something like: select case when isInteger('4') is true then cast('4' as int) else null end as mycolumn;

Comments

  • During imports I'll typically use regexp_like for this and check for non-digit characters, e.g.
    select regexp_like('abc', '[^0-9]');
    true
    select regexp_like('1234', '[^0-9]');
    false

Leave a Comment

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