Ambiguous column reference in block_box_get()
kg9ov - January 13, 2007 - 18:30
| Project: | Drupal |
| Version: | 5.x-dev |
| Component: | block.module |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
After adding a new block and saving, going back to configure the block results in an empty form.
pg_query(): Query failed: ERROR: column reference "title" is ambiguous in /var/www/drupal/drupal-5.0-rc2/includes/database.pgsql.inc on line 125.
query: SELECT bx.*, title FROM boxes bx INNER JOIN blocks bl ON bx.bid = bl.delta WHERE module = 'block' AND bid = 5 in /var/www/drupal/drupal-5.0-rc2/includes/database.pgsql.inc on line 144.Adding bl reference to "title" column in block_box_get() fixes this on my install.
# diff block.module.orig block.module
362c362
< return db_fetch_array(db_query("SELECT bx.*, title FROM {boxes} bx INNER JOIN {blocks} bl ON bx.bid = bl.delta WHERE module = 'block' AND bid = %d", $bid));
---
> return db_fetch_array(db_query("SELECT bx.*, bl.title FROM {boxes} bx INNER JOIN {blocks} bl ON bx.bid = bl.delta WHERE module = 'block' AND bid = %d", $bid));Server
OS: Debian 3.1 (Sarge)
Web Server: Apache 2.0.54
PHP: 4.3.10
DB: Postgres 7.4.7
Drupal: 5.0rc2

#1
The problem seems to still exist in Drupal 5.0 Release.
Server
OS: Windows XP SP2
Web Server: Apache 2.2.4
PHP: 5.2.0
DB: Postgres 8.2
Drupal: 5.0
Best regards,
John
#2
We have just experienced this problem.
The issue can be resolved by changing line 362 to
return db_fetch_array(db_query("SELECT bx.*, bx.title FROM {boxes} bx INNER JOIN {blocks} bl ON bx.bid = bl.delta WHERE module = 'block' AND bid = %d", $bid));I'll add this to a patch in a minute.
#3
Patch implemented ready for review
#4
That last file didn't upload correctly ... this one should be ok
#5
I had get the same messages in drupal 5.1 on the site I'm working on....
* warning: pg_query() [function.pg-query]: Query failed: ERROR: column reference "title" is ambiguous LINE 1: SELECT bx.*, title FROM boxes bx INNER JOIN blocks bl ON bx.... ^ in /var/www/virtual-drake/drake-prod/includes/database.pgsql.inc on line 125.
* user warning: query: SELECT bx.*, title FROM boxes bx INNER JOIN blocks bl ON bx.bid = bl.delta WHERE module = 'block' AND bid = 1 in /var/www/virtual-drake/drake-prod/includes/database.pgsql.inc on line 144.
Thanks for the info on how to patch.
#6
The same patch fixed it for me
Drupal 5.1
PostgreSQL 8.2
#7
That should be
bl.titlenotbx.title. It is the blocks table that has the title field and not the boxes table. Attached patch also adds missing aliases in other parts of the query.Please review and set to "Ready to be committed" if the attached patch works for you. I'm not sure how adding bx.title worked for anybody as that should have spat out an unknown field error.
FYI: I've tested this only on MySQL.
Thanks,
-K
#8
P.S. The above patch applies on both 6 and 5 with offsets.
#9
The cause here may be the drop column query in system.install isn't being executed in system_update_1006(). That was the case for me, although the rest of that update did go through (dropping the constraint, etc).
#10
Ah, can you guys look at the drop-query too? Let's make sure we're fixing the problem at the right level, eh. :)
#11
@Dries: The pgSQL query in question appears to be OK. However, there were other inconsistencies with the syntax and I've created an issue for it: http://drupal.org/node/138556
http://drupal.org/node/132775 (a dupe) also has the same fix. Marking this RTBC.
-K
#12
I'm getting the same error on MySQL and this patch corrects it.
#13
Just for future searchers, I'm getting this error as a side effect of the query:
PHP Fatal error: Unsupported operand types in D:\drupal\drupalhead\modules\block\block.module on line 592#14
Committed to CVS HEAD. I think this needs to go into Drupal 5 too.
#15
Committed to 5.
#16
#17