On Apr 13, 12:28 pm, Phil Crosby <[email protected]> wrote:
> Hey Jeremy, thanks for your alternative; I'll try it shortly. For
> completeness, here is the stacktrace + SQL log:
>
> movies = Movie.join(:movies_labels, :movie_id => :id).limit(1).first
>   (0.00) SELECT * FROM `movies` INNER JOIN `movies_labels` ON
> (`movies_labels`.`movie_id` = `movies`.`id`) LIMIT
>
> (works correctly)
>
> movies = Movie.join(:movies_labels, :movie_id => :id).limit(1).count
>
> (0.00) Mysql::Error: Duplicate column name 'updated_at': SELECT
> COUNT(*) AS `count` FROM (SELECT * FROM `movies` INNER JOIN
> `movies_labels` ON (`movies_labels`.`movie_id` = `movies`.`id`) LIMIT
> 1) AS `t1` LIMIT 1

There's the difference, you added a .limit(1).  When you count on a
limited dataset, you get a subselect.  Are you really sure that's the
query you want to do?  It should return only 0 or 1.

The fact that you get a duplicate column name is a MySQL bug in my
opinion.  Neither PostgreSQL nor SQLite appear to have an issue with
duplicate columns names in a subselect if they are not referenced by
anything.  My advice is to use a database that sucks less. :)

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to