[development] hook_install: pgsql: check version number

Daniel Convissor danielc at analysisandsolutions.com
Mon Mar 6 14:44:57 UTC 2006

On Mon, Mar 06, 2006 at 11:23:27AM +0100, Keve wrote:
> Hi,
> I am not very familiar with Postgresql.
> I wrote taxonomy_access.install file, but for POSTGRESQL priot to 8.0, I 
> need to make a BIT_OR aggregate function.
> Do you think this will work OK for pg?
>      if (version_compare(pg_version(), '8.0', '<')) {
>           // PRIOR TO POSTGRESQL 8.0: making a BIT_OR aggregate function
>      }

That has problems.  Here's something that I've put together for the update 
process, though it has not been incorporated yet.  Then there's similar 
thinking for the install process.  Considering the need to know server 
version numbers in several places, I hope code along the following lines 
gets incorporated into database.inc:

function get_db_server_version() {
  static $version;

  if (isset($version)) {
    return $version;

  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      if (function_exists('mysql_get_server_info')) {
        // Since:  MySQL library: 4.0.1-alpha,  PHP: 4.0.5.
        $version = mysql_get_server_info($GLOBALS['active_db']);
      else {
        $row = db_fetch_object(db_query('SELECT version() AS version'));
        $version = $row->version;
      $version = str_replace(array('-debug','-max','-nt','-opt'), '', $version);
    case 'pgsql':
       * Not using pg_version() because it is only available in PHP 5 and with
       * PostgreSQL library: 7.4.  More importantly, the 'server_version'
       * is missing, at least in PHP 5.1.2.
      $row = db_fetch_object(db_query('SELECT version() AS version'));
      $version = preg_replace('/^[^0-9]+([^ ]+).*/i', '\\1', $row->version);
      $version = 0;
  return $version;


 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409

More information about the development mailing list