Ambiguous column name in SQL literal query

1,102 views
Skip to first unread message

Mauro

unread,
Apr 27, 2009, 12:00:24 PM4/27/09
to sqlalchemy
Dear group,

I'm having the following issue with "Ambiguous column name", in this
situation:

#code example begin

connString = 'sqlite:///data/prosafelocal.sqlite'
engine = create_engine(connString)
connection = engine.connect()
query = 'SELECT crfItem.idCrf, crfItem.idClass, class.name,
attribute.id, attribute.name from crfItem JOIN class ON
crfItem.idClass = class.id JOIN attribute on class.id =
attribute.idClass WHERE crfItem.idCrf = 1'

result = self.connection.execute(query, use_labels=True)

#code end


I'm using connection.execute(query) directly with literal sql syntax.
I get the following error:

"try 'use_labels' option on select statement." % colname)
InvalidRequestError: Ambiguous column name 'name' in result set! try
'use_labels' option on select statement."

The "name" column is present in two joint tables, and it generates the
ambiguity.
Anyway, it seems like the option "use_labels=True" does is not
affecting my query behaviour.
Any help would be really appreciated.

Thanks,
Mauro




Michael Bayer

unread,
Apr 27, 2009, 1:16:23 PM4/27/09
to sqlal...@googlegroups.com

use_labels is a flag used by a select() construct. this is a literal text
expression, so just label your "name" column something else, i.e.
"class.name AS class_name".

a...@svilendobrev.com

unread,
Apr 27, 2009, 1:29:12 PM4/27/09
to sqlal...@googlegroups.com
as the SQl is literal, u have to apply that advice by hand:
SELECT crfItem.idCrf, class.name as clsname, attribute.name as
attrname ...
or something of sorts
Reply all
Reply to author
Forward
0 new messages