New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text() construct generated for autogen on create_index w/ real column expression includes table name, fails #337

Closed
sqlalchemy-bot opened this Issue Oct 30, 2015 · 10 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Oct 30, 2015

Migrated issue, originally created by roy enjoy (@kirpit)

The following operation is failing and postgresql complains about its syntax.

op.create_index('ix_publish_at', 'cms_video', [sa.text(u'cms_video.publish_at DESC')], unique=False)

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) syntax error at or near "DESC" LINE 1: ...INDEX ix_publish_at ON cms_video (cms_video.publish_at DESC)

publish_at is a simply DateTime field and here is the index definition:
Index('ix_publish_at', publish_at.desc())

I created the revision file with --autogenerate.

I found an exact same question but it seems he had old version of psql running. My postgresql was installed with brew and its version is 9.4.4 that should be enough to support desc indexes. Tried with alembic==0.8.3, I don't know what is wrong.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2015

Michael Bayer (@zzzeek) wrote:

hi there -

this is a usage question - please use the mailing list for questions thanks!

the list passed to create_index are column expressions, they aren't table qualified:

op.create_index(
    'ix_publish_at', 'cms_video',
    [sa.text("publish_at DESC")], unique=False)
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2015

Changes by Michael Bayer (@zzzeek):

  • added labels: invalid
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2015

Michael Bayer (@zzzeek) wrote:

oh, autogenerate is generating this, fine. you need to correct this manually for now.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2015

Changes by Michael Bayer (@zzzeek):

  • removed labels: invalid
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2015

Changes by Michael Bayer (@zzzeek):

  • added labels: autogenerate - rendering
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2015

Changes by Michael Bayer (@zzzeek):

  • changed title from "Error creating DESC index on Postgresql" to "text() construct generated for autogen on create_i"
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2015

Michael Bayer (@zzzeek) wrote:

seems like postgres accepts an expression like:

CREATE INDEX ix_publish_at ON cms_video (lower(cms_video.publish_at))

but we can remove the table qualification on these as well.

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2015

Michael Bayer (@zzzeek) wrote:

  • Adjusted the rendering for index expressions such that a :class:.Column
    object present in the source :class:.Index will not be rendered
    as table-qualified; e.g. the column name will be rendered alone.
    Table-qualified names here were failing on systems such as Postgresql.
    fixes #337

e88a366

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 30, 2015

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Nov 1, 2015

roy enjoy (@kirpit) wrote:

Thanks @zzzeek, much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment