Java org.postgresql.util.PSQLException:错误:函数st_dwithin(几何体,双精度,双精度)不存在

Java org.postgresql.util.PSQLException:错误:函数st_dwithin(几何体,双精度,双精度)不存在,java,postgresql,spring-boot,postgis,Java,Postgresql,Spring Boot,Postgis,我想让所有商店靠近一个特定的位置,但似乎我有一个查询字符串的问题。我已经检查过postgis的版本是postgis 2.5.22。我还检查了经度和纬度是否具有双精度 我的数据库具有以下结构: 我曾尝试将查询重写为不同的查询字符串,但仍然出现相同的错误 我的实体: @Entity @Table(name = "seller_geolocation_ms") public class Seller_Geolocation { @Id @GeneratedValue(strateg

我想让所有商店靠近一个特定的位置,但似乎我有一个查询字符串的问题。我已经检查过postgis的版本是postgis 2.5.22。我还检查了经度和纬度是否具有双精度

我的数据库具有以下结构:

我曾尝试将查询重写为不同的查询字符串,但仍然出现相同的错误

我的实体:

@Entity
@Table(name = "seller_geolocation_ms")
public class Seller_Geolocation {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private static final long serialVersionUID = 2L;

    private double latitude;
    private double longitude;
    private String country;
    private String cityName;
    private String zipCode;
    private String town;
    private String address;
    private Long sellerId;

    @JsonIgnore
    @Column(columnDefinition = "geometry")
    private com.vividsolutions.jts.geom.Point location;

}

我的存储界面:

@Repository
public interface SellerGeolocationRepository extends CrudRepository<Seller_Geolocation, Long> {

    @Query(value="SELECT * FROM seller_geolocation_ms WHERE ST_DWithin(location,?1,?2) = true", nativeQuery = true)
    public Set<Seller_Geolocation> findAllSellersInRange(double longitude, double latitude);

}
在postgres数据库中工作,但在java应用程序中返回错误:

org.postgresql.util.PSQLException:错误:语法错误位于或接近“:”

检查两个几何图形之间的距离是否在给定范围内。它将2个几何体和一个距离作为参数

行SQL将是

选择*
从myTable
其中ST_DWithin(mytable.geom,ST_SetGrid(ST_Point,经度,纬度),4326),距离(度);
现在这将需要一个以度为单位的距离。要使用以米为单位的距离,您可以重新投影到以米为单位的CRS,也可以投射到地理位置

选择*
从myTable
其中ST_DWithin(mytable.geom::geography,ST_SetGrid)(ST_Point(经度,纬度),4326)::地理,距离(米);
或者使用另一种与地理位置不同的方式:

选择*
从myTable
其中ST_DWithin(cast(mytable.geom as geography),ST_SetGrid(ST_Point(经度,纬度),4326):地理,距离,米;

谢谢你的回答,但是在第二个查询中,你有geom,我不确定那是什么,因为当我尝试直接在数据库中运行查询时,它会显示未知列geom,这是一个常用名称。。。使用您的几何列名(可能是
location
?)尝试运行此SELECT*FROM seller_geology_ms WHERE ST_DWithin(seller_geology_ms.location::geography,ST_SetSRID(ST_Point(59.393181,5.286147),4326)::geography,215000);从我的springboot应用程序中,我得到了错误org.postgresql.util.PSQLException:error:syntax error at或near:“是否有其他方法来编写查询的这部分seller\u geolocation\u ms.location::geography您可以尝试
cast(seller\u geolocation\u ms.location as geography)
    public Set<Seller_Geolocation> getAllSellersInLocation(Double longitude, Double latitude) {
        return sellerRepository.findAllSellersInRange(longitude, latitude);
    }

SELECT * 
FROM seller_geolocation_ms 
WHERE ST_DWithin(location::geography, ST_SetSRID(ST_Point(59.393181, 5.286147), 4326), 30000);