Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

java - Using Collection in PGSQL native Query in Spring Data as parameter

Is it possible to use it as says topic?

    @Query("select p as payment from Payment p" +
        " left join Payment pp on pp = p" +
        " where p.uploadData.user = :user " +
        " and p.uploadData.active = false " +
        " and p.timestamp >= :timestamp_from " +
        " and p.timestamp < :timestamp_to " +
        " and (concat(p.address.building.building, ', ',p.address.apartment) in (case when :addressNull = true then concat(p.address.building.building, ', ',p.address.apartment)  else :addressList end))" +
        " and (concat(p.account.account,'') in (case when  :accountNull = true then concat(p.account.account,'') else :accountList end))" +
        " and (concat(p.service.service,'') in (case when  :serviceNull = true then concat(p.service.service,'') else :serviceList end))")
List<Payment> findAllUsingTimestampAndFilter(@Param("user") User user,
                                             @Param("timestamp_from") ZonedDateTime from,
                                             @Param("timestamp_to") ZonedDateTime to,
                                             @Param("addressList") Collection<String> address,
                                             @Param("accountList") Collection<String> account,
                                             @Param("serviceList") Collection<String> service,
                                             @Param("addressNull") boolean addressFlag,
                                             @Param("accountNull") boolean accountFlag,
                                             @Param("serviceNull") boolean serviceFlag);

When i'm using it this way, i'm getting an error when any collection parameter contains more than one item in it.

org.postgresql.util.PSQLException: ERROR: CASE types record and text cannot be matched
Position: 1061

Already tried

...(:serviceNull or (p.service.service in :serviceList))

and got another error.

Simplifying, i tried a lot of things, but still getting errors. Anyone have idea, how can to fix it?

P.S. Sorry, if there's error in my post, it's my first question on stackoverflow and my english is not so good.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...