SQL Server's isNumeric() equivalent in amazon redshift

后端 未结 8 1943
庸人自扰
庸人自扰 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 02:53

    It seems that redshift doesn't support any of the following:

    where left(field1,4) like '[0-9][0-9][0-9][0-9]' 
    where left(field1,4) ~ '^[0-9]{4}'
    where left(field1,4) like '^[0-9]{4}'
    

    what does seem to work is:

    where left(field1,4) between 0 and 9999
    

    this returns all rows that start with four numeric characters.

    it seems that even though field1 is type string, the 'between' function interprets left(field1,4) as a single integer when the string characters are numeric (and does not give an error when they are not numeric). I'll follow up if I find a problem. For instance I don't deal with anything less than 1000, so I assume, but am not sure, that 0001 is interpreted as 1.

提交回复
热议问题