【问题标题】:postgres-error: function st_intersects(geography, geography, integer) does not existpostgres 错误:函数 st_intersects(geography, geography, integer) 不存在
【发布时间】:2020-06-12 21:38:43
【问题描述】:

我有一个带有 postGIS 位置列的表 business_locations,我尝试获取边界框内的行(函数参数)。

我正在尝试在 Hasura 中运行此功能:

CREATE OR REPLACE FUNCTION search_businesses_near_project(lngW integer, latS integer, lngE integer, latN integer)
RETURNS SETOF business_locations AS $$
  SELECT  A.location, A.route, A.locality, A.administrative_area_level_1, A.administrative_area_level_2, A.country, A.business_id
  FROM business_locations A where ST_Intersects(A.location::geography, ST_MakeEnvelope(lngW, latS, lngE, latN, 4326)::geography, 4326)
$$ LANGUAGE sql STABLE;

返回的错误:

{
    "internal": {
        "statement": "CREATE OR REPLACE FUNCTION search_businesses_near_project(project_location geography, lngW integer, latS integer, lngE integer, latN integer)\r\nRETURNS SETOF business_locations AS $$\r\n  SELECT  A.location, A.route, A.locality, A.administrative_area_level_1, A.administrative_area_level_2, A.country, A.business_id\r\n  FROM business_locations A where ST_Intersects(project_location, ST_MakeEnvelope(lngW, latS, lngE, latN, 4326)::geography, 4326)\r\n$$ LANGUAGE sql STABLE;",
        "prepared": false,
        "error": {
            "exec_status": "FatalError",
            "hint": "No function matches the given name and argument types. You might need to add explicit type casts.",
            "message": "function st_intersects(geography, geography, integer) does not exist",
            "status_code": "42883",
            "description": null
        },
        "arguments": []
    },
    "path": "$.args[0].args",
    "error": "query execution failed",
    "code": "postgres-error"
}

【问题讨论】:

    标签: postgresql postgis hasura


    【解决方案1】:

    st_intersects 只接受两个参数。省略多余的 SRID:

    CREATE OR REPLACE FUNCTION search_businesses_near_project(
       lngW integer,
       latS integer,
       lngE integer,
       latN integer
    ) RETURNS SETOF business_locations AS $$
       SELECT *
       FROM business_locations A
       WHERE st_intersects(
                A.location::geography,
                ST_MakeEnvelope(lngW, latS, lngE, latN, 4326)::geography
       )
    $$ LANGUAGE sql STABLE;
    

    【讨论】:

    • 谢谢它有效,但现在我收到此错误:`“消息”:“声明返回业务位置的函数中的返回类型不匹配”,“状态代码”:“42P13”,“描述”:“最终语句返回的列太少。"`。不能只返回几列吗?我也全部退货了?
    • 适当地转换结果:SELECT ROW(a.location, a.route, ...)::business_locations
    • 它不起作用。我得到Cannot cast type geography to uuid in column 1。我使用的是SELECT ROW(a.location, a.business_id)::business_locationsbusiness_locations 表中的第一列是 uuid 类型,其名称为 id
    • 那你应该RETURN business_locations FROM business_locations WHERE ....
    • 在哈苏拉你只能返回SETOF,所以也许不可能。我不能确切地说,因为我是 postgres 的新手。 hasura.io/docs/1.0/graphql/manual/schema/custom-functions.html
    猜你喜欢
    • 2021-02-15
    • 2015-11-20
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    相关资源
    最近更新 更多