Check if key exists in a JSON with PL/pgSQL?

前端 未结 4 1533
时光说笑
时光说笑 2021-01-12 22:18

I\'m trying to check if a key exists in a JSON sent as parameter in a PL/pgSQL function.

Here is the function.

CREATE FUNCTION sp_update_user(user_in         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-12 22:28

    Another way to check if a JSON key exists is with json_extract_path(). Here's an example use:

    SELECT permit_id FROM building_permits WHERE
    json_extract_path(containing_boundaries, 'neighborhood') IS NULL
    

    This looks for a property in your JSON object ("containing_boundaries") called "neighborhood". If the property does not exist, it returns NULL.

提交回复
热议问题