這是我的原始查詢,它適用于針對同一數據庫的pg_admin:WITH myconstants (nb_pieces,nb_room,is_fiber) as ( values (0,0,true) )SELECT pbuy.name, seller.name as seller_name, fiche.fiberFROM on_plan_buy pbuyINNER JOIN card_fiche fiche ON pbuy.uuid = fiche.ad_uuidINNER JOIN on_plan_seller seller ON pbuy.seller_id = seller.idINNER JOIN myconstants conste ON trueWHERE pbuy.code_insee IN ('92108','75018') AND pbuy.price <= 9999999 AND pbuy.price >= 0 AND CASE WHEN conste.is_fiber = false THEN true ELSE fiche.fiber = true ENDLIMIT 100;但是當我在golang中這樣做時:query = `WITH myconstants (nb_pieces,nb_room,is_fiber) as ( values ($3,$4,$5) )SELECT pbuy.nameFROM ` + tableOnPlan + ` pbuyINNER JOIN card_fiche fiche ON pbuy.uuid = fiche.ad_uuidINNER JOIN myconstants conste ON trueWHERE pbuy.code_insee IN ('` + strings.Join(gsm.CodeInsee, "','") + `') AND pbuy.price <= $1 AND pbuy.price >= $2 AND CASE WHEN conste.is_fiber = false THEN true ELSE fiche.fiber = true ENDLIMIT 100;`//AND CASE WHEN conste.nb_pieces = 0 THEN pbuy.piece > 0 ELSE pbuy.piece = conste.nb_pieces END//AND CASE WHEN conste.nb_room = 0 THEN pbuy.chambre > 0 ELSE pbuy.chambre = conste.nb_room END//AND CASE WHEN conste.is_fiber = false THEN true ELSE fiche.fiber = true ENDfmt.Println(query)err = db.Select(&response.Offers, query, gsm.PriceMax, gsm.PriceMin, gsm.NbRoom, gsm.NbChamber, gsm.Fiber)
PSQL 運算符在 postgresql 中不存在
慕蓋茨4494581
2022-08-24 16:07:39