PostgreSQL之Json型別使用總結
待查詢資料庫“json”欄位內容
表名:tablename
欄位名:json
{
“CXX”: “北京市”,
“CRE”: “1”,
“CEE”: “oop”,
“IEOE”: [
{
“AAA”: “2882”,
“BBB”: “1”,
“CCC”: null,
“DDD”: “1245”,
“EEE”: -1,
“FFF”: 1
},
{
“AAA2”: “123”,
“BBB”: null,
“CCC”: “123456”,
“DDD”: “1234567”,
“EEE”: -1,
“FFF”: 1
}
],
“CFFFF”: “5555”,
“CGGGG”: “8”,
“CJJJJ”: “2323”,
“COOOO”: “23”,
“CFSDF”: “333”,
}
如果想要查詢CXX的內容:
SELECT json->>’CXX’ as cxx FROM tablename;
查詢IEOE下面的AAA的內容:
SELECT (json->’IEOE’)#>>’{0,AAA}’ as aaa FROM tablename ;
查詢IEOE下面的AAA2的內容:
SELECT (json->’IEOE’)#>>’{1,AAA2}’ as aaa FROM tablename ;
當json欄位裡面的內容要作為where條件查詢時,同樣道理:
SELECT (json->’IEOE’)#>>’{1,AAA2}’ as aaa FROM tablename WHERE ( (json->’IEOE’)#>>’{1,AAA2}’) = ‘……’;