dimazest wrote:
> Hi all,
>
> I faced a problem comparing Selects. It seems that Select.compare()
> works incorrectly.
>
> Here is the code that shows the problem:
>
>>>> from sqlalchemy import MetaData
>>>> from sqlalchemy import Table, Column
>>>> from sqlalchemy import Integer, String
>>>> from sqlalchemy import select
>>>> metadata = MetaData()
>>>> table1 = Table('table1', metadata,
> ... Column('col1', Integer, primary_key=True),
> ... )
>>>> s1 = select([table1])
>>>> s2 = select([table1])
>>>> assert s1.compare(s2)
> Traceback (most recent call last):
>   File "<input>", line 1, in <module>
> AssertionError
>
> Do I expect correctly that s1.compare(s2) should return True? If not,
> how can I compare to Selects?

compare() is documented as producing an identity compare by default, i.e.
s1.compare(s1) would be True.   "compare()" is currently only used by the
ORM for comparing the structure of column expressions and is not generally
useful on a FromClause at this time.

for a simple comparison of any two elements, just do:

def compare(x, y):
   x = x.compile()
   y = y.compile()
   return unicode(x) == unicode(y) and x.params == y.params






>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+unsubscr...@googlegroups.com.
> 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 sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to