>>The Query should return to you tuples that have names like "row_num" and
"test_msg", which are linked to the "anon" names that >>it generates:
>> for row in myquery:
>> print row.row_num, row.test_msg
>>that is, the "anon_x" names do not matter. they are an artifact of how
the Query does its work and the result rows are translated >>back to the
constructs you gave it originally.
If i have method as below
def second_method(self):
for tbl in Table: ---- for loop is used
since we have 3 tables and doing union of them
qry = some_method()
query = query.union_all(qry) if query else qry
return result_query
def some_method(self):
query = self.session.query(Table.row_num.label('row_num'),
Table.test_msg.label('test_msg'),
Table.crt_dt.label('crt_dt'),
Table2.name_file.label('name_file')).join(
(Table2, Table2.some_idn == Table.some_idn))
return query
record = second_method()
The above method returns the query object . when we try record[0] we will
get the result set
[(1, None, datetime.datetime(2011, 2, 24, 12, 37, 58, 123000), 'test.txt')]
when i try to get the keys record[0].__dict__.keys() it gives the result
[u'%(215049772 anon)s_name_file', u'%(215049772 anon)s_crt_dt',
u'%(215049772 anon)s_row_num', '_labels', u'%(215049772 anon)s_test_msg']
so as you mentioned in previous mail if i try
for row in record:
print row.row_num, row.test_msg
i am getting the attribute error : *** AttributeError: 'NamedTuple'
object has no attribute 'row_num'
On Mon, Apr 18, 2011 at 4:40 PM, Michael Bayer <[email protected]>wrote:
>
> On Apr 18, 2011, at 1:50 AM, monster jacker wrote:
>
> Hi Micheal,
>>
> As per your comment you want to say this issue whatever i am
> facing is resolved in 0.7 version of sqlalchemy?
> If i use the 0.7beta version this issue can be resolved?
>
>
> that is the case
>
>
>
> What i actually want to say is since i am refering in the code the
> column names as "row_num " but the query after the union is aliasing it as
> anon_1.anon_2_row_num so we are not getting any result set.
>
>
> I dont understand what "not getting any result set means". Here is the
> structure you showed me:
>
> select * from
> (
> select * from table1
> union all
> select * from table3
> ) as anon2
> union all
> select * from table4
> ) as anon1
>
> this looks kind of like you're saying
> query.union_all(query2).union_all(query3). UNION ALL is entirely
> commutative and associative. The above returns the equivalent rows as:
>
> select * from table1 union all select * from table3 union all select * from
> table4
>
> so you should get the same number of result rows as if no aliasing were
> used.
>
>
> if i change the code with "anon_1.anon_2_row_num" at that time if there
> are more than 2 unions at that time i wil get
> "anon_1.anon_2_anon_3_row_num" at that time will get the same issue what i
> am facing.so i want to know is there any way so that i can avoid aliasing
> as "anon_1_anon_2_row_num" for all the columns at the top level query.
>
>
> The Query should return to you tuples that have names like "row_num" and
> "test_msg", which are linked to the "anon" names that it generates:
>
> for row in myquery:
> print row.row_num, row.test_msg
>
> that is, the "anon_x" names do not matter. they are an artifact of how the
> Query does its work and the result rows are translated back to the
> constructs you gave it originally.
>
> If you'd like a SQL string that is constructed to an exact specification,
> use the SQL expression language instead of the ORM Query object.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" 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/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en.