commit update join支持@cast字段类型转换 #785
Merged
+15
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在实际业务场景中存在关联字段类型不一致的情况,目前的代码在left join关联时发现无法兼容字段类型不一致的情况,需要在sql中拼接cast函数进行转换
如:pg数据库A表id为int、B表id_str为varchar、C表id为int
打印出来的sql为:
SELECT "A".*, "B".*, "C".* FROM "public"."A" AS "A" LEFT JOIN ( SELECT * FROM "public"."B" ) AS "B" ON "B"."id_str" = "A"."id" LEFT JOIN ( SELECT * FROM "public"."C" ) AS "C" ON "C"."id" = "B"."id_str" LIMIT 20000导致出现类型不匹配的错误

修改代码兼容cast函数后
打印出来的sql为:
SELECT "A".*, "B".*, "C".* FROM "public"."A" AS "A" LEFT JOIN ( SELECT * FROM "public"."B" ) AS "B" ON CAST("B"."id_str" AS integer) = "A"."id" LEFT JOIN ( SELECT * FROM "public"."C" ) AS "C" ON CAST("C"."id" AS varchar) = "B"."id_str" LIMIT 20000数据响应成功
