16 Mayıs 2023 Salı

Jsonb ?& Array Operator - All String Exists

Giriş
Açıklaması şöyle
?& - Checks if all of the strings in the text array exist as top-level keys or array elements. So generally if we have JSON property that contains an array then you can check if it contains all elements that you are searching by.
Aynı şeyi SQL ile şöyle yaparız. jsonb_all_array_strings_exist kullanılır
CREATE OR REPLACE FUNCTION jsonb_all_array_strings_exist(jsonb, text[]) RETURNS boolean AS $$ SELECT $1 ?& $2; $$ LANGUAGE SQL; SELECT
item0_.id as id1_0_, item0_.jsonb_content as jsonb_co2_0_ FROM item item0_ WHERE jsonb_all_array_strings_exist(jsonb_extract_path(item0_.jsonb_content,?), array[?,?])=true

Hiç yorum yok:

Yorum Gönder