PostgreSQL Json field as query condition case

Business extension fields are often stored in json format data in the database, which involves a headache. Suppose you want to use a certain value in the extension field as a query condition. It turns out that PostgreSQL itself supports this query method. .

Example: Suppose the json format stored in the business extension field ext_data is as follows:

We need to query all the data of extInfo.userType=1 in the extended field, then the corresponding SQL statement is as follows:

select * from event_log where (ext_data::json#>>'{extInfo,userType}')::text = '1'

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325256784&siteId=291194637