【问题标题】:function st_intersects(bytea, bytea) is not unique函数 st_intersects(bytea, bytea) 不是唯一的
【发布时间】:2020-05-27 11:58:29
【问题描述】:

尝试合并两个表并将结果导出到 csv 文件时,我收到此错误,即function st_intersects(bytea, bytea) is not unique.

【问题讨论】:

标签: postgresql postgis


【解决方案1】:

问题是您为几何数据使用了错误的数据类型 (bytea)。

PostgreSQL 可以在 byteageometry / geography 之间隐式转换:

\dC bytea
                         List of casts
   Source type   | Target type |      Function      | Implicit? 
-----------------+-------------+--------------------+-----------
 bytea           | geography   | geography          | yes
 bytea           | geometry    | geometry           | yes
 geography       | bytea       | bytea              | yes
 geometry        | bytea       | bytea              | yes
[...]
(7 rows)

现在有三个函数st_intersects

\df st_intersects
                                  List of functions
 Schema |     Name      | Result data type |       Argument data types        | Type 
--------+---------------+------------------+----------------------------------+------
 public | st_intersects | boolean          | geog1 geography, geog2 geography | func
 public | st_intersects | boolean          | geom1 geometry, geom2 geometry   | func
 public | st_intersects | boolean          | text, text                       | func
(3 rows)

现在在其function type resolution rules 之后,PostgreSQL 无法确定您需要这些函数中的第一个还是第二个,这会导致错误消息。

解决方案:

  1. 在表定义中使用适当的数据类型(geometrygeography)。

  2. 使用显式强制转换,就像错误消息告诉你的那样:

    st_intersects(CAST (g1 AS geometry), CAST (g2 AS geometry))
    

我认为 PostGIS 将两种类型都设为隐式是一个糟糕的选择。

【讨论】:

    猜你喜欢
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 2014-01-12
    • 2012-02-25
    • 2011-06-29
    • 1970-01-01
    • 2023-01-08
    相关资源
    最近更新 更多