我想要获取值的哪些部分的ID是在一个定义的列表中。比方说,我们有一个称为表ABC
PostgreSQL字符串的一部分是在一个数组中
CREATE TABLE abc
AS
SELECT post_id
FROM (VALUES
('868164246578472_912876412107255'),
('868164246578472_912883258773237'),
('868164246578472_913049595423270')
) AS t(post_id);
然后,我只取部分下划线
select (regexp_split_to_array(element_id, '_'))[2] as element_id from ABC limit 3;
element_id
-----------------
912876412107255
912883258773237
913049595423270
现在我想只拿那些元素,在那里他们element_ids是一个定义列表但后我没有得到任何结果
select (regexp_split_to_array(post_id, '_'))[2] as post_id from ABC where post_id = ANY('{912876412107255, 912883258773237}'::text[]) limit 3;
post_id
---------
(0 rows)
我也试过这样:
select (regexp_split_to_array(post_id, '_'))[2]::text[] as post_id from ABC where post_id IN ('912876412107255', '912876412107255') limit 3;
post_id
---------
(0 rows)
表的结构如下:
Table "public.ABC"
Column | Type | Modifiers
---------------+-----------------------------+------------------------------------------------------
id | integer | not null default nextval('ABC_id_seq'::regclass)
element_id | text | not null
where子句? (不认为这是允许的) 此外,为什么只有1个元素时,将选定的表达式放入数组中。 –
@JoeLove:这是不允许的。这就是为什么戈德里克失败的原因。 – kmkaplan
是的,谢谢。我想通了,并立即发布答案 – Godric