Postgres CTE返回null,regexp_split_to_array也为空

时间:2018-06-08 19:54:26

标签: postgresql

WITH cte as ( 
    SELECT partnerlist as a FROM support.members WHERE id = 'BB36' 
) 

SELECT REGEXP_SPLIT_TO_ARRAY('BB36,'||(SELECT a FROM cte), ',')

cte返回null,没有行。

为什么regexp_split_to_array不会返回[BB36]

在我的完整查询中,它在where子句中使用:

AND u.id = any(regexp_split_to_array('BB36,'||(SELECT a FROM cte), ','))

1 个答案:

答案 0 :(得分:0)

将CTE更改为此功能使其正常工作:

WITH cte as ( 
    SELECT 
        CASE WHEN partnerlist IS NULL OR urgpartnerslistori = '' THEN
            'XX99'
        ELSE 
            partnerlist 
        END as a 
    FROM support.members WHERE id = 'BB36' 
)