I had a little problem after upgrading from 4.7 to 5.1. I received a warning about ambiguous query after posting new content or editing an existing content:

user warning: Column 'tid' in field list is ambiguous query: SELECT tid FROM term_data LEFT JOIN term_data catd ON term_data.tid = catd.tid WHERE (term_data.tid IN (2, 0) OR catd.vid NOT IN (2)) ORDER BY tid LIMIT 305, 1 in C:\xampp\htdocs\drupal-5.1\includes\database.mysql.inc on line 172.

Obviously in this case, I don't need left join because the two tables are the same, so I had to add this check manually ($primary_table == 'term_data'):

// hack BEGIN
//$join = "LEFT JOIN {term_data} catd ON $primary_table.tid = catd.tid"; // commented out
if($primary_table == 'term_data')
$join = "";
else $join = "LEFT JOIN {term_data} catd ON $primary_table.tid = catd.tid";
// hack END

// hack BEGIN
//$where = "$primary_table.tid IN (". implode(', ', $tids) .") OR catd.vid NOT IN (". implode(',', $vids) .")"; // commented out
if($primary_table == 'term_data')
$where = "$primary_table.tid IN (". implode(', ', $tids) .") OR $primary_table.vid NOT IN (". implode(',', $vids) .")";
else
$where = "$primary_table.tid IN (". implode(', ', $tids) .") OR catd.vid NOT IN (". implode(',', $vids) .")";
// hack END

comes from: http://drupal.org/node/148316

Comments

Dave Cohen’s picture

Thanks for the report, and the hack idea. I'm not sure whether that's the best solution. Could be, but I'm not sure.

First, let's figure out what module is making this query. I'm guessing gsitemap. Do you have that installed? If not, what contrib and/or custom modules are installed?

erdtek’s picture

Hi, yes I have installed gsitemap.

amedee-1’s picture

I had exactly the same error.
I disabled gsitemap, and the error is gone.
I don't absolutely need gsitemap, but it would be a "nice to have".

Dave Cohen’s picture

Sounds like gsitemap is the problem. I'm not using it. Can one of you try to disambiguate the queries in gsitemap? Anywhere gsitemap uses "tid" in a query, replace it with {term_data}.tid. So for instance

        $tid = db_result(db_query_range(db_rewrite_sql('SELECT tid FROM {term_data} ORDER BY tid', 'term_data', 'tid'), $count - 1, 1));

Would become

        $tid = db_result(db_query_range(db_rewrite_sql('SELECT {term_data}.tid FROM {term_data} ORDER BY {term_data}.tid', 'term_data', 'tid'), $count - 1, 1));

Just looking through gsitemap.module I see several queries that could be ambiguous.

Dave Cohen’s picture

Status: Active » Fixed

Closing due to inactivity.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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