0

В PostgreSQL 9.4 имеется таблица с записями. Поле tags имеет тип JSONB. введите сюда описание изображения

Как получить, например, все записи у которых в поле tags имеется значение 1. Ниже привожу код и ошибку, которую он вызывает.

SELECT public.mytable.* FROM public.mytable WHERE tags ? 1;

ERROR: operator does not exist: jsonb ? integer LINE 1: SELECT public.mytable.* FROM public.mytable WHERE tags ? 1; ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. ********** Ошибка **********

ERROR: operator does not exist: jsonb ? integer SQL-состояние: 42883 Подсказка: No operator matches the given name and argument type(s). You might need to add explicit type casts. Символ: 52

1 ответ 1

1
select * from (select '[1,14,5]'::jsonb as q) as foo where q @> '[1]'::jsonb;
     q      
------------
 [1, 14, 5]
1
  • не забудь создать gin-овый индекс с jsonb_path_ops 6 окт 2015 в 14:35

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.