On Oct 20, 2011, at 3:54 PM, Jeremy Jones wrote:

> We are moving from mysql to postgres and would like to have the same
> sort behavior in postgres that mysql provides.  Unfortunately as the
> code was written for our application, it didn't always get an explicit
> "order by" because the behavior that was in mysql worked how it was
> "supposed to."  Is there any way that we can get sqlalchemy to enforce
> for postgres the "order by {{ primary key field }} nulls last" that we
> saw in mysql?  To add a wrinkle, we are using Elixir and not straight
> SQLAlchemy, but I suspect that we are going to have to address this at
> the SA level rather than the Elixir level.

mapper() accepts an "order_by" parameter that would provide, in simple cases, a 
default "order by" for a query() that doesn't otherwise specify "order_by".   
Similarly, relationship() also has an "order_by" parameter that provides for 
the ORDER BY to be used whenever a related collection is loaded.

Elixir should provide some mechanism to pass these configuration options down 
to the underlying mapper() and relationship() functions.

http://www.sqlalchemy.org/docs/orm/mapper_config.html#class-mapping-api
http://www.sqlalchemy.org/docs/orm/relationships.html#relationships-api

Generally any relationship() that's against a list-based collection should 
probably have the order_by parameter since Python lists themselves have a 
deterministic ordering.

the "nulls last" part, while available as an option, isn't needed here since a 
primary key value cannot be NULL.



-- 
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.

Reply via email to