From 55a671b9f7505d391bfd1cdaad29000567fa23e6 Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Sat, 6 Jun 2015 20:35:11 -0600 Subject: [PATCH] [nextgen-gallery] Convert GROUP_CONCAT() to STRING_AGG() PostgreSQL does not support the MySQL GROUP_CONCAT() aggregation function. This results in errors such as: Error running : SELECT DISTINCT wp_ngg_gallery.* , GROUP_CONCAT(CONCAT_WS('@@', meta_key, meta_value)) AS `extras` FROM `wp_ngg_gallery` LEFT OUTER JOIN `wp_postmeta` ON `wp_postmeta`.`post_id` = `extras_post_id` GROUP BY wp_ngg_gallery.gid ORDER BY `gid` ASC LIMIT 25 ---- converted to ---- SELECT DISTINCT wp_ngg_gallery.* , GROUP_CONCAT(CONCAT_WS('@@', meta_key, meta_value)) AS extras FROM wp_ngg_gallery LEFT OUTER JOIN wp_postmeta ON wp_postmeta.post_id = extras_post_id GROUP BY wp_ngg_gallery.gid ORDER BY gid ASC LIMIT 25 ----> ERROR: function group_concat(text) does not exist LINE 1: SELECT DISTINCT wp_ngg_gallery.* , GROUP_CONCAT(CONCAT_WS('@... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. However, PostgreSQL 9.0 and later provide the STRING_AGG() aggregation function for the same purpose. Therefore, replace calls to GROUP_CONCAT() with STRING_AGG(). Signed-off-by: Kevin Locke --- pg4wp/driver_pgsql.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pg4wp/driver_pgsql.php b/pg4wp/driver_pgsql.php index 2d7a522..16c84f9 100644 --- a/pg4wp/driver_pgsql.php +++ b/pg4wp/driver_pgsql.php @@ -249,6 +249,9 @@ $pattern = '/DATE_ADD[ ]*\(([^,]+),([^\)]+)\)/'; $sql = preg_replace( $pattern, '($1 + $2)', $sql); + + $pattern = '/GROUP_CONCAT\(([^()]*(\(((?>[^()]+)|(?-2))*\))?[^()]*)\)/x'; + $sql = preg_replace( $pattern, "string_agg($1, ',')", $sql); // UNIX_TIMESTAMP in MYSQL returns an integer $pattern = '/UNIX_TIMESTAMP\(([^\)]+)\)/';