The Vertica Forum recently got a makeover! Let us know what you think by filling out this short survey.

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

Can't find what you're looking for? Search the Vertica Documentation, Knowledge Base, or Blog for more information.