【发布时间】:2015-06-04 02:47:01
【问题描述】:
我想从我的数据库中选择所有行,其中一行包含一组单词/数组中的至少两个术语。
例如: 我有以下数组:
'{"test", "god", "safe", "name", "hello", "pray", "stay", "word", "peopl", "rain", "lord", "make", "life", "hope", "whatever", "makes", "strong", "stop", "give", "television"}'
我得到了一个存储在数据库中的推文数据集。所以我想知道哪些推文(列名:tweet.content)至少包含 两个字词。
我当前的代码看起来像这样(当然它只选择一个词...):
CREATE OR REPLACE VIEW tweet_selection AS
SELECT tweet.id, tweet.content, tweet.username, tweet.geometry,
FROM tweet
WHERE tweet.topic_indicator > 0.15::double precision
AND string_to_array(lower(tweet.content)) = ANY(SELECT '{"test", "god", "safe", "name", "hello", "pray", "stay", "word", "peopl", "rain", "lord", "make", "life", "hope", "whatever", "makes", "strong", "stop", "give", "television"}'::text[])
所以最后一行需要以某种方式进行调整,但我不知道如何 - 也许是内部连接?!
我将单词也以唯一的 id 存储在不同的表中。
我的一个朋友建议对每一行进行计数,但我没有在原始表中添加额外列的写入权限。
背景:
我将我的推文存储在 postgres 数据库中,并在数据集上应用了 LDA(潜在狄利克雷分配)。现在我得到了生成的主题和与每个主题相关的词(20 个主题和 25 个词)。
【问题讨论】:
-
@mu 太短 id = 整数
-
@mu 是数据库的标准公共架构太短... 推文结构 id = integer userid = bigint i> username = text tweetcontent_raw = text tweetcontent = text (stemmed tweets) tweetdate = _timestamp with time zone the_geom = geometry i> 存储单词的表(results_lda): oid topic_id = integer word = text topic_probability = double precision
-
sry 我的会话被中断了
-
和 tweetcontent 的内容(这是我感兴趣的专栏)看起来是这样的:首先学习如何让自己快乐 ...仅作为示例...
标签: sql arrays postgresql select twitter