1. 从以下地址复制emoji的unicode https://unicode.org/emoji/charts/full-emoji-list.html
2. 建立字典表
代码语言:javascript复制create table emoji_unicode(c varchar(10));
copy emoji_unicode from '/data/emoji_unicode.txt';
alter table emoji_unicode add column e varchar(10);
update emoji_unicode set e=chr(cast(cast(('x' || c) as bit(16)) as int));
select * from emoji_unicode;
c | e
------- ---
2755 | ❕
1F43B | ὃ
1F450 | ὅ
1F9B5 | ᾛ
1F1FC |
1F34B | ἴ
1F1F9 |
1F693 | Ὡ
1F355 | ἵ
23EC | ⏬
......
1F004 | ἀ
1FAB0 | ᾫ
1F63A | ὣ
1F532 | ὓ
1F606 | ὠ
1F982 | ᾘ
1F35F | ἵ
1F995 | ᾙ
1F646 | ὤ
1FAC5 | ᾬ
(1432 rows)
3. 查询测试
代码语言:javascript复制-- 源数据
SELECT x.content FROM x WHERE CommentID in (39539523,39205786);
-- 关联查询
SELECT distinct x.content FROM x, emoji_unicode
WHERE CommentID in (39539523,39205786) and x.content like '%'||e||'%';
结果如下:
字典表关联一个四千二百万行的评论表,其中评论字段 content 数据类型为 varchar(6000),查询出所有带 emoji 的评论,用时25分钟。