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 <kevin@kevinlocke.name>
This commit is contained in:
Kevin Locke
2017-09-24 14:17:31 -06:00
parent f896bb1759
commit 54042c1bcc

View File

@ -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\(([^\)]+)\)/';