Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
Update of the metatag module to 7.x-1.0-beta5 (from beta4) generates on a PSQL database following error:
Update #7007
Failed: PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "m" LINE 1: DELETE m ^: DELETE m FROM {metatag} m LEFT OUTER JOIN {node} n ON m.entity_id=n.nid WHERE m.entity_type='node' AND n.nid IS NULL; Array ( ) in metatag_update_7007() (Zeile 325 von /var/www/(…)/sites/all/modules/metatag/metatag.install).
Drupal 7.21, PSQL 8.4.16, Apache/2.2.14 (Ubuntu)
Comment | File | Size | Author |
---|---|---|---|
#44 | metatag-n1953724-44.patch | 5.54 KB | DamienMcKenna |
#43 | metatag-n1953724-43.patch | 5.58 KB | DamienMcKenna |
#41 | metatag-n1953724-41.patch | 4.81 KB | DamienMcKenna |
#39 | metatag-n1953724-39.patch | 987 bytes | DamienMcKenna |
#36 | updated metatag_update_7011 to use UPDATE FROM syntax | 668 bytes | joshf |
Comments
Comment #1
DamienMcKenna:-\
The purpose of this query is to join the {metatag} and {node} tables together and delete anything in {metatag} that doesn't have a matching record in {node}. I don't have PostgreSQL installed, if you have any ideas on how to handle this query I'd love to hear it. Thanks.
Comment #2
twistor CreditAttribution: twistor commentedWould something like this work? It is frowned upon to do DELETE queries with db_query(). I haven't tested this at all.
Comment #3
traveller CreditAttribution: traveller commentedSorry, I'm not able to test it now. For one website I just uninstalled the module and installed it again (as I didn't lose any data in the process), but I wouldn't like to do it for another bigger installation, without being forced to reconfigure the metadata again.
Comment #4
wiifmAlso getting the error on PostgreSQL 9.1.8, my SQL skills are not good enough to fix this though.
Comment #5
DamienMcKennaClosed a duplicate: #1955598: Error updating db last update
Comment #6
Jibus CreditAttribution: Jibus commentedI encouter the same problem
Comment #7
jim.applebee CreditAttribution: jim.applebee commentedTraveller - were you able to resolve this issue with reinstalling the meta tags module? Is it currently working?
Comment #8
twistor CreditAttribution: twistor commentedI don't have Postgres lying around to test this on, but here's a patch.
Comment #10
twistor CreditAttribution: twistor commentedApply to dev.
Comment #11
twistor CreditAttribution: twistor commented#8: metatag-sql-syntax-error-1953724-8.patch queued for re-testing.
Comment #12
Jibus CreditAttribution: Jibus commentedTested the patch, when updating the db, i got this error message :
Fatal error: Call to a member function isNull() on a non-object in /usr/local/www/sites/all/modules/metatag/metatag.install on line 324
Comment #13
twistor CreditAttribution: twistor commentedOy, this should fix that.
Comment #14
Jibus CreditAttribution: Jibus commentedThanks for you help Twistor !
- Tested patch #13,
- Applied patch metatag.install cleanly
Update #7007 result with this error
Failed: PDOException : SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "SELECT" LINE 2: WHERE (entity_type = 'node') AND (entity_id = SELECT m.enti... ^: DELETE FROM {metatag} WHERE (entity_type = :db_condition_placeholder_0) AND (entity_id = SELECT m.entity_id AS entity_id FROM {metatag} m LEFT OUTER JOIN {node} n ON m.entity_id=n.nid WHERE (m.entity_type = :db_condition_placeholder_1) AND (n.nid IS NULL ) ) ; Array ( [:db_condition_placeholder_0] => node [:db_condition_placeholder_1] => node ) dans metatag_update_7007() (ligne 329 dans /usr/local/www/sites/all/modules/metatag/metatag.install).
Comment #15
DamienMcKennaI think this is the correct approach - build a separate list of entity IDs using a SELECT statement, then delete those values. Obviously, please test this on a *copy* of your site, just in case =)
Comment #16
Jibus CreditAttribution: Jibus commentedThanks for your time :)
Patch applied cleanly (3 lines add whitespace errors)
Now it's the #7008 update which fails :
Update #7008
Failed: PDOException : SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "m" LINE 1: DELETE m FROM metatag m WHERE m.data IS NULL or m.data = '' ... ^: DELETE m FROM {metatag} m WHERE m.data IS NULL or m.data = '' OR m.data = :empty; Array ( [:empty] => a:0:{} ) dans metatag_update_7008() (ligne 388 dans /usr/local/www/sites/all/modules/metatag/metatag.install).
Probably the same error ?
Comment #17
DamienMcKennaTry these patches, they remove the 'm' from after 'delete'.
Comment #18
twistor CreditAttribution: twistor commentedYeah, that's where I was going. You can't DELETE from the same table that you SELECT from. The 2 queries is annoying though.
The only alternative I can come up with would be to use different db_query()'s based on the driver. :(
Comment #19
DamienMcKenna@twistor: It's not that much of a big deal, I'm going to test the patch on MySQL too and then will commit the changes so it's in the next release.
Comment #20
twistor CreditAttribution: twistor commentedm.entity_id
@DamienMcKenn I know. I'm just anal.
Comment #21
DamienMcKenna@twistor: That's perfectly reasonable - there's only one "entity_id" field, thus no chance of confusion as to which one is being referenced, but it's best to specify the table anyway.
Comment #22
twistor CreditAttribution: twistor commentedAhh, well. Seeing as how I've been zero help on this issue, I will shut up now :)
Comment #23
DamienMcKenna@twistor: There's no need for self-deprecation, you've helped. You can even help a little more - does the patch in #21 work for you? :)
Comment #24
wiifm@DamienMcKenna your patch at #21 did not apply using drush make, so I have re-made it (hopefully this is a little better now).
Update hooks 7007 and 7008 work now, but not 7009
Getting closer
Comment #25
twistor CreditAttribution: twistor commentedhaha, it works on MySQL.
Comment #26
wiifmPlease do not change the status, this issue clearly still needs work as the latest "stable" release does not work on PostgreSQL. I am aware the module maintainer uses MySQL ;)
Comment #27
DamienMcKenna@wiifm: Does this one work?
Comment #28
DamienMcKennaSimplifying the title.
Comment #29
DamienMcKennaTagging.
Comment #30
twistor CreditAttribution: twistor commented@wiifm, that was a cross-post. Although, I'm not sure what a stable release has to do with anything.
Comment #31
wiifm@DamienMcKenna bumped to --dev, and then drush make will apply your patch, now it gets passed 7009 and stuck on 7014:
Comment #32
DamienMcKennaThis should resolve update 7014.
Comment #33
wiifmCan confirm this does resolved any exceptions
Happy to RTBC this for now as it is a giant leap over what is currently on --dev.
Comment #34
DamienMcKennaThank you all for the help debugging this, I've committed the fix and will be releasing beta6 very soon.
Comment #35
Jibus CreditAttribution: Jibus commentedTested the 7.x-1.x-dev 2013-Apr-05 release.
I have this error :
Update #7011
Failed: PDOException : SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "INNER" LINE 1: UPDATE metatag AS m INNER JOIN node n ON m.entity_id=n.nid A... ^: UPDATE {metatag} AS m INNER JOIN {node} n ON m.entity_id=n.nid AND m.entity_type='node' SET m.language = n.language; Array ( ) dans metatag_update_7011() (ligne 440 dans /usr/local/www/sites/all/modules/metatag/metatag.install).
Comment #36
joshf CreditAttribution: joshf commentedHere's a patch for the error described in #35, which I also got.
Comment #37
DamienMcKenna@joshf: Thanks for helping. That query really works? That's some strange SQL :-) We need to test it on MySQL before committing it, just in case.
Comment #38
joshf CreditAttribution: joshf commented@ DamienMcKenna Thanks for the module!
Yeah, see http://www.nexusdb.com/forums/showthread.php?t=16473#4 it looks like neither one of these are actually SQL compliant. I have doubts about sqlite's ability to parse this, as well. I'll test that when I can and maybe come up with a less efficient but more cross-compatible two-query fix.
Comment #39
DamienMcKennaThis should resolve the problem with metatag_update_7011().
Comment #40
DamienMcKennaAck, #39 won't work, it needs to run a loop via batch_api otherwise it'll time out - that's what I was hoping to avoid with the more advanced query.
Comment #41
DamienMcKennaLets try this - it loops over 20 records at a time and only updates records that have a different language.
Comment #42
DamienMcKennaComment #43
DamienMcKennaI tested #41 with MySQL and found a problem with the DELETE statement in update 7008, so this fixes that.
Comment #44
DamienMcKennaA small improvement to metatag_update_7011.
Comment #45
Jibus CreditAttribution: Jibus commentedA big thanks for your work :)
- Tested patch #44,
- Applied patch metatag.install cleanly
No duplicate node records were found (this is a good thing).
There were no other records to fix.
No corrupt records to fix, this is good news :-)
The following updates returned messages
metatag module
Update #7011
No nodes need the Metatag language values fixed.
Update #7013
No meta tag records need updating.
Thanks !
Comment #46
DamienMcKennaExcellent. Committed!
Comment #47
jlnknz CreditAttribution: jlnknz commentedJust a note to let you know that the patched metatag.install file also fixes updates with an sqlite database.
The error occuring on update #7007 was the following:
Comment #48
DamienMcKenna@clrdd: Good to know, thanks :)
Comment #49
lookas CreditAttribution: lookas commentedA had similar problem with PostgreSQL, and i've used DBTNG Migrator. I've just migrated PQSQL to MySQL and all updatest are done ok.
So I probably wont get back to PostgreSQL.
Comment #50
dfurman CreditAttribution: dfurman commentedIs there an aggregate path or release scheduled? I'm experiencing all described problems with the updates.
Comment #51
Jibus CreditAttribution: Jibus commentedYou can use the latest dev version
Comment #52
DamienMcKenna1.0-beta6 is out, so I'm closing this issue in the interest of keeping the issue queue clean.