Postgresql 如何将“不相似”与查询结果一起用作模式
我有这两张桌子 一,- 第二个呢Postgresql 如何将“不相似”与查询结果一起用作模式,postgresql,Postgresql,我有这两张桌子 一,- 第二个呢 DROP TABLE IF EXISTS filter_test ; CRATE TABLE filter_test ( config_key text, config_value text ); INSERET INTO filter_test select 'BLACKLIST_NAMES' , 'david,ran'; INSERET INTO filter_test select 'FILTER' , 'di,ja,aap'; 我想写一
DROP TABLE IF EXISTS filter_test ;
CRATE TABLE filter_test (
config_key text,
config_value text
);
INSERET INTO filter_test select 'BLACKLIST_NAMES' , 'david,ran';
INSERET INTO filter_test select 'FILTER' , 'di,ja,aap';
我想写一个查询,从random\u data
返回不在BLACKLIST\u name
中的filter\u test
表中的名称,其中描述
不包含filter
我能够像这样完成第一部分:
SELECT* from random_data where name not in (with t as (
SELECT
max(case when config_key = 'BLACKLIST_NAMES' then config_value::text end) as names_blacklist
-- max(case when config_key = 'BLACKLIST_NAME_FILTERS' then config_value::text end) as BLACKLIST_NAME_FILTERS
from filter_test
)
select
regexp_split_to_table(names_blacklist, ',') as names
from t
) order by name;
select * from random_data where name not in (with t as (
select
max(case when config_key = 'BLACKLIST_NAMES' then config_value::text end) as names_blacklist
from filter_test
)
select
regexp_split_to_table(names_blacklist, ',') as names
from t
) and discription not like (with t as (
select
max(case when config_key = 'BLACKLIST_NAME_FILTERS' then config_value::text end) as filters
from filter_test
)
select
regexp_split_to_table(filters, ',') as filter
from t
)order by name
但我无法完成第二部分,
我试着这样做:
SELECT* from random_data where name not in (with t as (
SELECT
max(case when config_key = 'BLACKLIST_NAMES' then config_value::text end) as names_blacklist
-- max(case when config_key = 'BLACKLIST_NAME_FILTERS' then config_value::text end) as BLACKLIST_NAME_FILTERS
from filter_test
)
select
regexp_split_to_table(names_blacklist, ',') as names
from t
) order by name;
select * from random_data where name not in (with t as (
select
max(case when config_key = 'BLACKLIST_NAMES' then config_value::text end) as names_blacklist
from filter_test
)
select
regexp_split_to_table(names_blacklist, ',') as names
from t
) and discription not like (with t as (
select
max(case when config_key = 'BLACKLIST_NAME_FILTERS' then config_value::text end) as filters
from filter_test
)
select
regexp_split_to_table(filters, ',') as filter
from t
)order by name
预期产量
**name** **discription**
mosh walker
这是你要找的吗
查询结果只需是
mosh walker
,因为FILTER
中的di
需要过滤diver
upd