如何在vectorwise中过滤掉具有特殊字符的数据

时间:2015-05-05 07:14:29

标签: special-characters ingres vectorwise

我的产品表中有一个名为Prod_code的列。 我需要从product表中只选择有效的prod_code并将其加载到另一个表中。 有效的prod_code是不包含任何特殊字符的代码。

VALID prod_code: WER1234,ASD1345

INVALID prod_code: ABC $ 123,LPS ????,$$$(我需要检查并过滤掉)。
我怎样才能做到这一点?

产品代码的Src列表

WER1234
ASD1345

产品代码目标列表

var searchByPhone = new List<Tuple<string,string>>();
searchByPhone.Add(Tuple.Create("12324344", "message one"));
searchByPhone.Add(Tuple.Create("45646565", "message two"));
searchByPhone.Add(Tuple.Create("56868675", "message three"));

//you should already have this list populated somehow, i'm declaring it here just for the sake of making the code compile
var clientlist = new List<Client>();

//this list will hold your results
List<ClientObject> resultList = new List<ClientObject>();


searchByPhone.ForEach(tp => resultList.AddRange(
                clientlist.Where(cl => cl.phones.Any(ph=>ph.phoneno == tp.Item1)).Select(cl => new ClientObject {id = cl.id, firstname = cl.firstname, lastname = cl.lastname, message = tp.Item2, phonenumber = tp.Item1}).ToList()));

1 个答案:

答案 0 :(得分:0)

这很可怕,但它确实起作用了。它使用LIKE谓词来拒绝不可接受的字符串。您也可以使用SIMILAR TO谓词来指定可接受的字符串,但我猜想LIKE更快。

select prod_code from products
where prod_code not like '%\['+x'00'+'-'+x'2f'+','+
                               x'3a'+'-'+x'40'+','+
                               x'5d'+'-'+x'7f'+'\]%' escape '\'
 and prod_code not like '%\%'
 and prod_code not like '%[%'