I made a view using the Location module to find nodes with a certain circular proximity of another node. I used the following as an example: http://drupal.org/node/359463

The Location module queries the database (Postgresql my case) using the IFNULL function. Postgresql however requires explicit typecasting when calling this function. This causes Drupal to generate an error:

warning: pg_query() [function.pg-query]: Query failed: ERROR: function ifnull(double precision, numeric) does not exist LINE 4: (IFNULL(ACOS(0.601815023152*COS(RADIANS(location.latitude... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. in /home/publish/www/includes/database.pgsql.inc on line 139.

user warning: query: SELECT location.lid AS lid, node.title AS node_title, node.nid AS node_nid, (IFNULL(ACOS(0.601815023152*COS(RADIANS(location.latitude))*(0.993571855677*COS(RADIANS(location.longitude)) + 0.113203213768*SIN(RADIANS(location.longitude))) + 0.798635510047*SIN(RADIANS(location.latitude))), 0.00000)*6364472.58123) AS location_distance_1 FROM location location LEFT JOIN location_instance location_instance ON location.lid = location_instance.lid LEFT JOIN node node ON location_instance.vid = node.vid WHERE (node.status <> 0) AND (node.type in ('kennisbron')) AND (location.latitude > 52.9549878024 AND location.latitude < 53.0450121976 AND location.longitude > 6.42520591205 AND location.longitude < 6.57479408795) AND ((IFNULL(ACOS(0.601815023152*COS(RADIANS(location.latitude))*(0.993571855677*COS(RADIANS(location.longitude)) + 0.113203213768*SIN(RADIANS(location.longitude))) + 0.798635510047*SIN(RADIANS(location.latitude))), 0.00000)*6364472.58123) < 5000) ORDER BY location_distance_1 ASC LIMIT 10 OFFSET 0 in /home/publish/www/modules/views/includes/view.inc on line 731.

I replaced the call for the IFNULL function with COALESCE, in earth.inc on line 123. Now the view works fine. COALESCE is also supported by other databases, including MySQL. IFNULL is a MySQL function and therefore shouldn't be used.

Comments

Anonymous’s picture

Added the issue to the bug queue of the Location module http://drupal.org/node/1008976.

liam morland’s picture

Issue tags: +PostgreSQL

Tagging

mdupont’s picture

Status: Active » Closed (duplicate)

Not related to Drupal core, so marking as duplicate of #1008976: PostgreSQL chokes on earth_distance_sql