About 16,300,000 results
Open links in new tab
  1. sql - postgresql: Filter in JSON array - Stack Overflow

    Dec 3, 2018 · You can use EXISTS function to filter sub json data. SELECT s.* FROM students s WHERE EXISTS( SELECT 1 FROM json_array_elements ( attributes ) as att WHERE att ->> 'value' ILIKE 'Foo%')

  2. How to filter JSON array in Postgres - Stack Overflow

    Jun 21, 2017 · Alternatively you can use jsonb_agg (read more at Postgres Aggregate Functions) instead of array_to_json + array_agg to provide same result like: SELECT jsonb_agg( t.* ) FILTER ( WHERE t.tag IS NOT NULL ) ( 'a1' ), ( 'b1' ), ( null ), ( 'c1' ), ( null ), ( 'd1' ) ) t( tag ); Thank you, the filter really worked.

  3. postgresql - How to filter json array per each returned row?

    Jul 17, 2014 · You can use json_array_elements to unnest JSON and array_agg to nest it back after filtering. Something like this: SELECT t.id, array_to_json(array_agg(j)) FROM your_table t, json_array_elements(t.jsonColumn) j WHERE j->>'field' = 'abc' GROUP BY id;

  4. postgresql - How to filter rows based on a nested JSON array

    Jan 26, 2023 · The idea is to filter rows of the tables based on the value of the expression field. For example, I might want to only leave the rows where there is a column where expression equals foo. My first idea was to use json_array_elements() multiple times and then write a WHERE EXISTS(SELECT true FROM ...) clause but

  5. PostgreSQL Querying & Filtering JSON Fields - DataCamp

    JSON functions are used in PostgreSQL to access and filter JSON data stored in columns of type `JSON` or `JSONB`. They enable complex data retrieval and manipulation by providing methods to extract elements, filter arrays, and modify JSON objects.

  6. postgresql - How do I select by a JSONB array containing at least …

    Aug 30, 2019 · There is (strangely) no function or operator to convert a JSONB array to a PostgreSQL array, you need a helper function to do that: RETURNS int[] LANGUAGE sql. IMMUTABLE. (select jsonb_array_elements($1)) as f(x); Once that is in place, you can use the ANY feature of PostgreSQL:

  7. How to Check if a JSON Array Contains a Specific Element in PostgreSQL

    Jan 29, 2025 · Learn how to efficiently query JSON arrays in PostgreSQL to determine the existence of specific elements using various SQL techniques.

  8. How to Query a JSON Column in PostgreSQL - PopSQL

    Learn how to effectively query JSON columns in PostgreSQL. Explore techniques for extracting specific JSON keys, filtering rows based on JSON data criteria, handling nested JSON structures, and troubleshooting common issues to master the art of …

  9. postgresql - How can I filter by jsonb object value inside array ...

    Jun 1, 2021 · When I want to filter by the meta.foo.bar value, I can do this: select * from tbl where meta->foo->>bar = 'baz'; Now let's say I want to make the foo an array of objects instead:

  10. PostgreSQL JSON Querying: Syntax and Examples - w3resource

    Dec 23, 2024 · Learn how to query JSON data in PostgreSQL using JSON operators and functions. Includes syntax, examples, and filtering tips for efficient JSON data handling.

  11. Some results have been removed
Refresh