SQL Server's isNumeric() equivalent in amazon redshift

后端 未结 8 1952
庸人自扰
庸人自扰 2021-01-04 02:17
  • I\'m using amazon redshift as my data warehouse
  • I have a field (field1)of type string. Some of the strings start with four numbers and others with letters:
8条回答
  •  庸人自扰
    2021-01-04 02:45

    Although long time has passed since this question was asked I have not found an adequate response. So I feel obliged to share my solution which works fine on my Redshift cluster today (March 2016).

    The UDF function is:

    create or replace function isnumeric (aval VARCHAR(20000))
      returns bool
    IMMUTABLE 
    as $$
        try:
           x = int(aval);
        except:
           return (1==2);
        else:
           return (1==1);
    $$ language plpythonu;
    

    Usage would be:

    select isnumeric(mycolumn), * from mytable
        where isnumeric(mycolumn)=false
    

提交回复
热议问题