16 Mayıs 2023 Salı

Jsonb ?| Array Operator - Any Strings Exist

Giriş
Açıklaması şöyle
?| - Checks if any 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 at least of elements that you are searching by.
Aynı şeyi SQL ile şöyle yaparızjsonb_any_array_strings_exist kullanılır
CREATE OR REPLACE FUNCTION jsonb_any_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_any_array_strings_exist(jsonb_extract_path(item0_.jsonb_content,?), array[?,?])=true

Hiç yorum yok:

Yorum Gönder