Jak zrobić select z klauzulą array contains value w psql
Mam kolumnę arr
, która jest typu array
.
Muszę pobrać wiersze, gdzie arr
kolumna zawiera wartość s
To zapytanie:
SELECT * FROM table WHERE arr @> ARRAY['s']
Podaje błąd:
Dlaczego to nie działa?Błąd: operator nie istnieje: zmienny znak [] @ > tekst []
P. s. wiem o any()
operatorze, ale dlaczego @>
nie działa?
48
3 answers
Try
SELECT * FROM table WHERE arr @> ARRAY['s']::varchar[]
75
Author: Wojtas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-05-17 10:21:23
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-05-17 10:21:23
Zauważ, że może to również działać:
SELECT * FROM table WHERE s=ANY(array)
32
Author: AetherUnbound,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-04 01:02:35
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-04 01:02:35
SELECT * FROM table WHERE arr && '{s}'::text[];
Porównaj dwie tablice dla zabezpieczenia.
13
Author: vol7ron,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-30 21:25:38
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-30 21:25:38