[英]How to convert double quoted ids to single quoted ids so that it is queryable in postgres?
PostgreSQL版本:10.3
產品示意圖
id integer
data text
顏色圖
id integer
name text
產品的顏色以色號數組的形式存儲在數據中,例如:['1','2']。
我需要一個查詢,其中可以獲取特定產品的顏色ID和名稱。 嘗試過類似的操作並出現錯誤:
select id,name from colors where id in (select trim(data::json ->> 'color_ids','[]') from products where id = 1);
錯誤:運算符不存在:整數=文本
我嘗試了這個:
查詢:
select data::json ->> 'color_ids' from products where id = 1;
結果:
["2","5","6","14"]
查詢:
select trim(data::json ->> 'color_ids','[]') from products where id = 1;
結果:
"2","5","6","14"
我還建議將其設置為整數(int)。 當您放置替換物時,它起作用嗎?
replace (trim(data::json ->> 'color_ids','[]'), '"', '')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.