Not sure if this needs to be addressed in MostPopular or Drupal's db abstraction layer. I figured I would start here...
When you enable with PostgreSQL you will see an error:
Notice: Array to string conversion in DatabaseSchema_pgsql->createTableSql() (line 127 of /usr/share/drupal7/includes/database/pgsql/schema.inc).
PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "Array" LINE 10: PRIMARY KEY (sid, iid, Array) ^: CREATE TABLE {mostpopular_item} ( sid bigint CHECK (sid >= 0) NOT NULL, iid bigint CHECK (iid >= 0) NOT NULL, entity_id int NULL, entity_type varchar(32) NULL, path varchar(1024), url varchar(2048), title varchar(1024), count int NOT NULL, PRIMARY KEY (sid, iid, Array) ); Array ( ) in db_create_table() (line 2685 of /usr/share/drupal7/includes/database/database.inc).
This is caused by how the primary key and entity_url index for the mostpopular_item table are defined.
'primary key' => array( 'sid', 'iid', array('path', 50) ),
'indexes' => array(
'entity' => array( 'entity_type', 'entity_id', 'sid', 'iid' ),
'entity_url' => array( 'entity_type', 'entity_id', array('path', 50) , 'sid', 'iid' ),
The 'path' field is a varchar with a max length of 1024. But mostpopular only uses the first 50 chars of 'path' in the primary key and index. I am guessing here, but apparently the D7 db abstraction layer does not handle this correctly for postgreSQL?
My temporary 'bandaid so we could install MostPopular' was to just remove the array for the 'path' field and use the full field for the primary key and index like so. PostgreSQL was perfectly happy with this and since our site is not likely to have very long path values, I don't believe it will cause a big performance hit.
'primary key' => array( 'sid', 'iid', 'path' ),
'indexes' => array(
'entity' => array( 'entity_type', 'entity_id', 'sid', 'iid' ),
'entity_url' => array( 'entity_type', 'entity_id', 'path', 'sid', 'iid' ),
The better fix of course would be to handle this properly in the D7 db abstraction code I would think.
Comments
Comment #1
amarcus commentedAccording to the Drupal specs, passing an array into the index definition allows us to specify parameters, such as key length, for each element of a database index. I assume, however, that the pgsql adapter does not handle these definitions correctly.
I recommend that you create a bug report in the Drupal core pgsql issues queue, since I suspect this is not the only module that is impacted by this.