Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

查询tags 里的tag1的值,怎么做呢? #104

Open
xiebingmengg opened this issue Jan 11, 2022 · 3 comments
Open

查询tags 里的tag1的值,怎么做呢? #104

xiebingmengg opened this issue Jan 11, 2022 · 3 comments
Assignees

Comments

@xiebingmengg
Copy link

DB.Create(&User{
Name: "json-1",
Attributes: datatypes.JSON([]byte({"name": "jinzhu", "age": 18, "tags": ["tag1", "tag2"], "orgs": {"orga": "orga"}})),
}

查询tags里,是否有tag1,怎么做呢?谢谢!

@ghost
Copy link

ghost commented Apr 21, 2022

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

@ghost
Copy link

ghost commented Apr 21, 2022

and more

SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @@ '$.tags[*] == "qui"';

@ghost
Copy link

ghost commented Apr 28, 2022

or my project using

		result = common.NewDb.
			Raw("select *  from  gs_article where gs_article.tag_ids @> ? LIMIT ? OFFSET ? ", tagId, rpp, offset).
			Find(&blogDataList)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants