2014-01-08 34 views
3

我想在包含阿拉伯文和英文文本的postgres數據庫中搜索表格。例如:如何在postgresql中搜索不同的字符集?

id | content 
----------------- 
1 | دجاج  
2 | chicken 
3 | دجاج chicken 

結果會得到我的第3行

我想這與限制使用正則表達式的字符做的,但我不能找到一個乾淨的解決方案,以選擇兩個。我嘗試過:

SELECT regexp_matches(content, '^([x00-\xFF]+[a-zA-Z][x00-\xFF]+)*') 
FROM mg.messages; 

但是,這隻能匹配英文和{}內的一些非英文字符。

+2

你嘗試過什麼?你在哪裏找它?你的樣本數據和預期產出是什麼? – Rachcha

+0

@Rachcha你是對的。我編輯我的問題更有意義。 – Slamice

回答

1

我什麼都不知道一般的阿拉伯文字或RTL語言,但這個工作:

create table phrase (
    id serial, 
    phrase text 
); 

insert into phrase (phrase) values ('apple pie'); 
insert into phrase (phrase) values ('فطيرة التفاح'); 

select * 
from phrase 
where phrase like ('apple%') 
or phrase like ('فطيرة%'); 

http://sqlfiddle.com/#!15/75b29/2