datatypes
datatypes copied to clipboard
查询tags 里的tag1的值,怎么做呢?
DB.Create(&User{
Name: "json-1",
Attributes: datatypes.JSON([]byte({"name": "jinzhu", "age": 18, "tags": ["tag1", "tag2"], "orgs": {"orga": "orga"}}
)),
}
查询tags里,是否有tag1,怎么做呢?谢谢!
the same question here. how to query a tag is in json array
https://www.postgresql.org/docs/current/datatype-json.html
-- Find documents in which the key "tags" contains key or array element "qui"
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc -> 'tags' ? 'qui';
ping @jinzhu
and more
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @@ '$.tags[*] == "qui"';
or my project using
result = common.NewDb.
Raw("select * from gs_article where gs_article.tag_ids @> ? LIMIT ? OFFSET ? ", tagId, rpp, offset).
Find(&blogDataList)