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

postgres dialect does produces wrong sql for schema names with extra dots #230

Closed
sqlalchemy-bot opened this Issue Oct 3, 2014 · 4 comments

Comments

Projects
None yet
1 participant
@sqlalchemy-bot

sqlalchemy-bot commented Oct 3, 2014

Migrated issue, originally created by John Janssen (@Sindol)

In a recent revision I tried to add a column to a certain schema in my postgres database, with a code something like this:

from alembic import op
import sqlalchemy as sa

op.add_column(mytablename, sa.Column(mycolname, sa.String), schema=myschemaname)

When myschemaname already has a dot (".") in it, this fails. For example for schemaname "my.schema" it produces:

ALTER TABLE "my".schema.mytablename ADD COLUMN mycolname VARCHAR

This returns an exception:
sqlalchemy.exc.NotSupportedError: (NotSupportedError) cross-database references are not implemented

Correct query would be:

ALTER TABLE "my.schema".mytablename ADD COLUMN mycolname VARCHAR
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 3, 2014

Changes by John Janssen (@Sindol):

  • edited description
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 3, 2014

Michael Bayer (@zzzeek) wrote:

  • Added support for use of the :class:~sqlalchemy.sql.elements.quoted_name
    construct when using the schema argument within operations. This
    allows a name containing a dot to be fully quoted, as well as to
    provide configurable quoting on a per-name basis.
    fixes #230

5bb97a4

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 3, 2014

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 3, 2014

Michael Bayer (@zzzeek) wrote:

here's the format:

from sqlalchemy.sql.schema import quoted_name
op.add_column("somename", sa.Column("colname", sa.String), schema=quoted_name("some.schema", quote=True))

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