mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-07-30 17:57:13 +02:00
[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 <kevin@kevinlocke.name>
This commit is contained in:
@ -250,6 +250,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\(([^\)]+)\)/';
|
||||
$sql = preg_replace( $pattern, 'ROUND(DATE_PART(\'epoch\',$1))', $sql);
|
||||
|
Reference in New Issue
Block a user