1

创建视图时,出现错误function populate_geometry_columns(unknown) is not unique。我正在阅读的一本书使用了这个,但它给了我一个错误。我可能出了什么问题?

询问:

CREATE OR REPLACE VIEW ch03.vw_paris_points AS
SELECT gid, osm_id, ar_num, geom,
tags->'name' As place_name,
tags->'tourism' As tourist_attraction
FROM ch03.paris_hetero
WHERE ST_GeometryType(geom) = 'ST_Point';

SELECT populate_geometry_columns('ch03.vw_paris_points');

错误:

ERROR:  function populate_geometry_columns(unknown) is not unique
LINE 1: SELECT populate_geometry_columns('ch03.vw_paris_points');
               ^
HINT:  Could not choose a best candidate function. You might need to add explicit type casts.

********** Error **********

ERROR: function populate_geometry_columns(unknown) is not unique
SQL state: 42725
Hint: Could not choose a best candidate function. You might need to add explicit type casts.
Character: 8
4

2 回答 2

8

来自精美手册

概要

text Populate_Geometry_Columns(boolean use_typmod=true);
int Populate_Geometry_Columns(oid relation_oid, boolean use_typmod=true);

因此,有两个可能的populate_geometry_columns函数可以用一个参数调用,但都没有 TEXT 参数。错误消息告诉您 PostgreSQL 不知道它是否应该将您的'ch03.vw_paris_points'字符串隐式转换为 aboolean或 an oid。我的人脑建议您需要以下oid版本:

SELECT populate_geometry_columns('ch03.vw_paris_points'::regclass);
-- add an explicit cast -------------------------------^^^^^^^^^^

但是 PostgreSQL 的软件大脑只看到一个字符串就会感到困惑。也许单参数形式populate_geometry_columns比您正在阅读的书要新。

于 2013-03-29T16:24:42.143 回答
2

PostgreSQL 允许函数重载。多个函数可以具有相同的名称。区别在于参数。

该手册详细说明了 PostgreSQL 的大脑如何尝试做出决定以及何时放弃像您这样的错误消息。@mu已经提供了此案例的详细信息。

于 2013-03-29T16:27:07.830 回答