Posts

Showing posts with the label amazon-redshift

Fixed length string comparison in Amazon Redshift

Fixed length string comparison in Amazon Redshift I have a table in Amazon Redshift called asmt.questions , which has a field called encodedids . This field is varchar and can have comma separated values. I would like to retreive all the records having any of the following values in them: Amazon Redshift asmt.questions encodedids varchar MAT.GEO.107 MAT.GEO.403 MAT.GEO.409.01 MAT.GEO.504.07 MAT.GEO.901.5 To achieve this, I wrote the following query: SELECT questionid, encodedids, irt_a FROM asmt.questions WHERE ispublic = TRUE AND encodedids similar TO '%(MAT.GEO.107|MAT.GEO.403|MAT.GEO.409.01|MAT.GEO.504.07|MAT.GEO.901.5)%' AND encodedids NOT similar TO '%(MAT.GEO.107.|MAT.GEO.403.|MAT.GEO.409.01.|MAT.GEO.504.07.|MAT.GEO.901.5.)%' AND irt_a IS NOT NULL ORDER BY encodedids, irt_a DESC This query does a decent job, but it also returns records having values like: MAT.GEO.10701 (note the added '01' in the end) MAT.GEO.40301 (note th...