Message in Log File:
error php Sep 5 2008 - 3:18pm query: ALTER TABLE uc_order_products ALTER model ... admin
query: ALTER TABLE uc_order_products ALTER model SET default in /srv/www/htdocs/drupal/includes/database.pgsql.inc on line 144.

error php Sep 5 2008 - 3:18pm pg_query(): Query failed: ERROR: syntax error at ... admin
pg_query(): Query failed: ERROR: syntax error at end of input at character 55 in /srv/www/htdocs/drupal/includes/database.pgsql.inc on line 125.

problem is in /drupal/sites/all/modules/ubercart/uc_order/uc_order.install:

Fixed by replacing '' with NULL (no quotes) as follows:

function uc_order_update_7() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_order_products} CHANGE model model VARCHAR(255) CHARACTER SET utf8 NOT NULL");
    break;
    case 'pgsql':
        // changing from 'default' => '' to 'default => NULL
      db_change_column($ret, 'uc_order_products', 'model', 'model', 'varchar(255)', array('not null' => TRUE, 'default' => NULL));
    break;
  }

  return $ret;
}

Comments

Island Usurper’s picture

Ugh. I had no idea that would be a problem.

I have to say, though, that changing the default value to NULL, when the column is supposed to be set "NOT NULL" doesn't sound like it will work in the long run. Instead we should specify the empty string with doubled quotes:

  db_change_column($ret, 'uc_order_products', 'model', 'model', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));

To make it clearer, that's " ' ' " after the 'default'. I just hope Postgres doesn't care whether we're using single or double quotes like that.

Island Usurper’s picture

*grumblings*

Schema API does the right thing and knows to wrap string default values in quotes....

mcgyver5’s picture

I think it is common to see a column created as NOT NULL with default value of NULL

the NOT_NULL will only come into play when something tries to insert a record.

Alternatively, what happens if we leave the 'default' parameter out of the array?

Island Usurper’s picture

Status: Active » Fixed

Oh never mind. I just can't read. It's probably only a problem in Drupal 5.x. The Schema API should handle it just fine in Drupal 6.

When you get the latest version of the code, you should be able to update with no problems.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.