如何使用返回记录集的函数运行嵌套查询?

时间:2018-03-26 11:59:51

标签: postgresql subquery

如何使用返回记录集的函数运行嵌套查询?

我想要做的是解析TEXT字段并将其拆分为词干。

它应该是这样的

with strings as (
    select text
    from messages
    where channel_id = 12345 and text like '%#%'
)
select distinct token
from ts_debug('russian', strings.text)
where alias = 'word';

但显然它不起作用,因为ts_debug返回记录集。

我该怎么做?

2 个答案:

答案 0 :(得分:1)

使用横向连接:

<div style={{ marginLeft: `${currentPer}%`, marginRight: `${100 - currentPer}%` }}>
  <div className={s.currentText}>
    {intl.formatMessage(messages.boo)}
  </div>
</div>
<div style={{ marginLeft: `${currentPer}%`, marginRight: `${100 - currentPer}%` }}>
  <div
    className={s.down}
  />
</div>

答案 1 :(得分:0)

可以将 strings.text 替换为(SELECT text FROM strings)

with strings as (
    select text
    from messages
    where channel_id = 12345 and text like '%#%'
)
select distinct token
from ts_debug('russian', (SELECT text FROM strings))
where alias = 'word';

或加入

with strings as (
    select text
    from messages
    where channel_id = 12345 and text like '%#%'
)
select distinct token
from strings 
INNER JOIN ts_debug('russian', strings.text) AS tsd ON true
where alias = 'word';