i18n schema update PostgreSQL incompatibility

plj - February 25, 2009 - 18:16
Project:Internationalization
Version:6.x-1.0
Component:Compatibility
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Issue tags:patch, upgrade path
Description

Schema update #9 of i18n.module attempts to run the following statements:

UPDATE {node} n INNER JOIN {i18n_node} i ON n.nid = i.nid SET n.language = i.language, n.tnid = i.trid
UPDATE {node} n SET n.tnid = (SELECT MIN(i.nid) FROM {i18n_node} i WHERE i.trid = n.tnid) WHERE n.tnid > 0

However, both will fail on PostgreSQL.

First one will, because JOINs and table aliases cannot be used on UPDATEs in standard SQL. The following works on PostgreSQL (I used it to fix my installation):

UPDATE {node} SET language={i18n_node}.language,tnid={i18n_node}.trid FROM {i18n_node} WHERE {node}.nid={i18n_node}.nid;

But this isn't any better as is, because PostgreSQL's UPDATE…FROM isn't standard syntax either, so there should be a case test for $GLOBALS['db_type'].

If that is not desireable, it should be possible to just run SELECT nid FROM {node} n.nid INNER JOIN {i18n_node} i ON n.nid=i.nid, and then update node table based on the results of that query. It is theoretically a bit slower, but a schema update isn't that common procedure anyway.

The second will succeed as it is if the table aliases are removed:

UPDATE {node} SET tnid = (SELECT MIN(i.nid) FROM {i18n_node} i WHERE i.trid = {node}.tnid) WHERE tnid > 0;

I'll see if I'll find time to create patch for these at some later date, but everything needed to fix the problem are stated above; I've tested the modified queries against PostgreSQL 8.1.

#1

hass - August 29, 2009 - 20:42
Status:active» needs work

No patch

#2

jandd - October 23, 2009 - 11:34
Status:needs work» needs review
Issue tags:+patch

I created the attached patch to implement the behavior described above. I tested the patch with Drupal 6.14 and PostgreSQL 8.3 (Debian Lenny)

AttachmentSize
0001-patch-for-update-9-on-PostgreSQL-fixes-383728.patch 2.08 KB

#3

Jose Reyero - November 24, 2009 - 16:07
Status:needs review» closed

This got committed into 6.x-1.2

Thanks.

 
 

Drupal is a registered trademark of Dries Buytaert.