PostGIS Error: Could not choose a best candidate function

£可爱£侵袭症+ 提交于 2020-01-05 07:38:09

问题


When creating a View, I get the error function populate_geometry_columns(unknown) is not unique. A book that I'm reading used this, but its giving me an error. What could have gone wrong for me?

Query:

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:

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

回答1:


From the fine manual:

Synopsis

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

So there are two possible populate_geometry_columns functions that could be called with one argument and neither has a TEXT argument. The error message is telling you that PostgreSQL doesn't know if it is supposed to implicitly cast your 'ch03.vw_paris_points' string to a boolean or an oid. My human brain suggests that you want the oid version:

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

but PostgreSQL's software brain just sees a string and gets confused. Perhaps the single argument form of populate_geometry_columns is newer than the book you're reading.




回答2:


PostgreSQL allows function overloading. More than one function can have the same name. The difference is in the parameters.

The manual details how PostgreSQL's brain tries to decide and when it gives up with an error message like yours. @mu already provided the details for this case.



来源:https://stackoverflow.com/questions/15706888/postgis-error-could-not-choose-a-best-candidate-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!