postgresql - Alternative to @> '["TEXT"]' syntax
问题描述
I have a JSONB
column with an array in it. I have a working query below.
However my language-specific implementation is failing because of the use of double quotes around EXAMPLESTRING
.
Here is the query:
SELECT
b0."id",
b0."base_sku",
b0."name",
b0."logo",
b0."email",
b0."active",
b0."building_group_id",
b0."operating_region_id",
b0."building_package_id",
b0."metadata",
b0."location",
b0."inserted_at",
b0."updated_at"
FROM "buildings" AS b0
WHERE (b0."metadata"->'google_place_ids' @> '["EXAMPLESTRING"]')
AND (b0."active" = TRUE)
LIMIT 1
I am looking for an alternative to this part of the query:
@> '["EXAMPLESTRING"]')
Is there any other way to write this?
解决方案
在你用你的框架或驱动程序解决这个潜在问题之前,你可能会度过一段非常不愉快的时光。
但是你可以像这样解决这个问题:
@> jsonb_build_array('EXAMPLESTRING')
您也可以使用“to_jsonb”函数,但这可能会给您的驱动程序带来更多的语法问题。
推荐阅读
- mysql - 慢速嵌套函数
- ruby-on-rails - Ruby on Rails - 设计向用户发送带有登录凭据的欢迎消息
- java - 如何使用来自 openjdk 的 Robot.mouseMove() 修复?
- javascript - 无法单击元素,量角器控制台中进一步没有错误显示
- version-control - 从错误的父级创建了一个命名分支
- c++ - 注释中的三元组,在 c++11 中转换,在 c++17 中被忽略
- google-maps - Google Maps API,获取搜索结果的边界
- postgresql - Postgresql 表/视图的本地缓存
- go - 两者中哪一个是惯用的方式?time.Sleep() 还是ticker?
- docker - 使用 Docker 的动态 Nginx 代理