Compare column entries in database query

1 view
Skip to first unread message

tor...@googlemail.com

unread,
Aug 2, 2007, 5:36:31 AM8/2/07
to Django users
Hi everybody!

I want to find all entries in a database where two specific fields are
equal:

mytable.objects.filter(column_a='column_b')

But this gives me no results at all. I now managed to get it done with
a .extra(), but I was wondering if this is the only possible solution.
All examples in the documentation work with static values for
comparison and there are no further details about the right hand side
of the query.

Thanks for reading!
Thomas.

P.S.:
Here's the query which get's the work done:
mytable.objects.extra(where=['column_a=column_b'])

Russell Keith-Magee

unread,
Aug 2, 2007, 7:25:49 AM8/2/07
to django...@googlegroups.com
On 8/2/07, tor...@googlemail.com <tor...@googlemail.com> wrote:
>
> I want to find all entries in a database where two specific fields are
> equal:
>
> mytable.objects.filter(column_a='column_b')

At present, the answer is unfortunately 'you can't do this' (unless
you use a hack like the one you mentioned).

I've had a few ideas on how to fix this; however, fixing this area of
code would require changes to an area that is currently undergoing a
major refactor. Once the query engine changes are complete, I have a
number of issues to address - this is one of them.

Yours,
Russ Magee %-)

tor...@googlemail.com

unread,
Aug 3, 2007, 5:14:16 PM8/3/07
to Django users
Hi Russ!

Thanks for the info! Saves me from trying around more.

Yours,
Thomas

On Aug 2, 1:25 pm, "Russell Keith-Magee" <freakboy3...@gmail.com>
wrote:

Reply all
Reply to author
Forward
0 new messages