Creating PostgreSQL Index with ASC/DESC and NULLS FIRST/LAST

558 views
Skip to first unread message

Florian Rüchel

unread,
Nov 23, 2015, 3:01:54 PM11/23/15
to sqlalchemy
Hey,

I want to execute the following statement in the most SQLAlchemy way possible:

CREATE INDEX ix_user_points ON "user" (points DESC NULLS LAST);

So I want to add a "DESC NULLS LAST" or equivalent as per documentation (http://www.postgresql.org/docs/current/static/indexes-ordering.html)

Can SQLAlchemy do this in any way and understand it? Alternatively: Where would be the correct spot to execute the explicit SQL? I was thinking about Schema Events here.

Regards,
Florian

Mike Bayer

unread,
Nov 23, 2015, 3:06:39 PM11/23/15
to sqlal...@googlegroups.com


On 11/23/2015 03:01 PM, Florian Rüchel wrote:
> Hey,
>
> I want to execute the following statement in the most SQLAlchemy way
> possible:
>
> CREATE INDEX ix_user_points ON "user" (points DESC NULLS LAST);
>
> So I want to add a "DESC NULLS LAST" or equivalent as per documentation
> (http://www.postgresql.org/docs/current/static/indexes-ordering.html)


this is supported directly

Index("ix_user_points", user.c.points.desc().nullslast())



>
> Can SQLAlchemy do this in any way and understand it? Alternatively:
> Where would be the correct spot to execute the explicit SQL? I was
> thinking about Schema Events here.
>
> Regards,
> Florian
>
> --
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlalchemy+...@googlegroups.com
> <mailto:sqlalchemy+...@googlegroups.com>.
> To post to this group, send email to sqlal...@googlegroups.com
> <mailto:sqlal...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

Florian Rüchel

unread,
Nov 23, 2015, 3:09:17 PM11/23/15
to sqlal...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages