我想要獲取值的哪些部分的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