From 54042c1bcc678d03203499a32ad9221e5934f845 Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Sun, 24 Sep 2017 14:17:31 -0600 Subject: [PATCH] Convert MySQL RAND() to PostgreSQL RANDOM() These functions are compatible, with the exception that MySQL RAND() optionally takes a seed argument. If future queries require seed support, a call to PostgreSQL SETSEED() can be added. Fixes: #12 Signed-off-by: Kevin Locke --- pg4wp/driver_pgsql.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pg4wp/driver_pgsql.php b/pg4wp/driver_pgsql.php index 375fd3a..785fdb7 100644 --- a/pg4wp/driver_pgsql.php +++ b/pg4wp/driver_pgsql.php @@ -299,6 +299,10 @@ $pattern = '/GROUP_CONCAT\(([^()]*(\(((?>[^()]+)|(?-2))*\))?[^()]*)\)/x'; $sql = preg_replace( $pattern, "string_agg($1, ',')", $sql); + + // Convert MySQL RAND function to PostgreSQL RANDOM function + $pattern = '/RAND[ ]*\([ ]*\)/'; + $sql = preg_replace( $pattern, 'RANDOM()', $sql); // UNIX_TIMESTAMP in MYSQL returns an integer $pattern = '/UNIX_TIMESTAMP\(([^\)]+)\)/';