i18n schema update PostgreSQL incompatibility
| Project: | Internationalization |
| Version: | 6.x-1.0 |
| Component: | Compatibility |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
| Issue tags: | patch, upgrade path |
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
No patch
#2
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)
#3
This got committed into 6.x-1.2
Thanks.